ot

package
v0.0.0-...-5f9c45b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TextEncodingTypeUTF8 = iota
	TextEncodingTypeUTF16
)

Variables

View Source
var (
	ErrOperationBaseLenMismatch = errors.New("ot/operation: base length mismatch")
	ErrOperationTransformFailed = errors.New("ot/operation: transform failed")
	ErrOperationMarshalFailed   = errors.New("ot/operation: marshal failed")
	ErrOpeartionUnmarshalFailed = errors.New("ot/operation: unmarshal failed")
)
View Source
var (
	ErrInvalidRevision = errors.New("ot/session: invalid revision")
)
View Source
var (
	ErrSelecttionUnmarshalFailed = errors.New("ot/selection: unmarshal failed")
)
View Source
var TextEncoding = TextEncodingTypeUTF8

use utf-8 by default

Functions

func IsDelete

func IsDelete(op *Op) bool

func IsInsert

func IsInsert(op *Op) bool

func IsRetain

func IsRetain(op *Op) bool

func OperationTransform

func OperationTransform(a, b *Operation) (*Operation, *Operation, error)

Types

type Client

type Client struct {
	Name      string    `json:"name"`
	Selection Selection `json:"selection"`
}

client info

type Op

type Op struct {
	N int
	S []rune
}

func (*Op) String

func (o *Op) String() string

type Operation

type Operation struct {
	Ops       []*Op
	BaseLen   int
	TargetLen int
	Meta      interface{}
}

func NewOperation

func NewOperation() *Operation

func OperationUnmarshal

func OperationUnmarshal(ops []interface{}) (*Operation, error)

func (*Operation) Apply

func (t *Operation) Apply(s string) (string, error)

func (*Operation) At

func (t *Operation) At(i int) *Op

func (*Operation) Delete

func (t *Operation) Delete(n int) *Operation

func (*Operation) Insert

func (t *Operation) Insert(s string) *Operation

func (*Operation) LastOp

func (t *Operation) LastOp() *Op

func (*Operation) Marshal

func (t *Operation) Marshal() []interface{}

func (*Operation) Retain

func (t *Operation) Retain(n int) *Operation

type Range

type Range struct {
	Anchor int `json:"anchor"`
	Head   int `json:"head"`
}

func (*Range) Transform

func (r *Range) Transform(op *Operation) *Range

type Selection

type Selection struct {
	Ranges []Range `json:"ranges"`
}

the selection range

func SelectionUnmarshal

func SelectionUnmarshal(data map[string]interface{}) (*Selection, error)

func (*Selection) SelectionMarshal

func (s *Selection) SelectionMarshal() map[string]interface{}

func (*Selection) Transform

func (s *Selection) Transform(op *Operation) *Selection

type Session

type Session struct {
	Document   string
	Operations []*Operation
	Clients    map[string]*Client
}

func NewSession

func NewSession(document string) *Session

func (*Session) AddClient

func (s *Session) AddClient(id string)

func (*Session) AddOperation

func (s *Session) AddOperation(revision int, op *Operation) (*Operation, error)

func (*Session) RemoveClient

func (s *Session) RemoveClient(id string)

func (*Session) SetName

func (s *Session) SetName(id, name string)

func (*Session) SetSelection

func (s *Session) SetSelection(id string, sel *Selection)

type TextEncodingType

type TextEncodingType int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL