riched

package
v0.0.0-...-917641f Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Editor

type Editor struct {
	Text          *rich.Text
	Focus, Anchor []interface{}
	Overrides     rich.Attrs
}

Editor wraps rich.Text with selection state and richer APIs

The current cursor position is stored in Focus and Achor, both of which must have atleast one element (the index into the root rich.Text) but can have more elements in the path when referring to embedded objects. Note that Anchor may be later in the rich.Text than Focus. Start() and End() return the earlier and later (respectively) of Focus and Anchor

The current set of inline styles (such as FontWeight) are stored in Overrides.

Editor itself is an immutable type which supports the changes.Value interface but it is not meant to be sent across the network as only the Text is meant to be collaborative.

All mutation methods return changes instead of mutating the underlying state. These can be applied to get the new value. Note that navigation is considered a mutation type as it modifies the state. Every mutation method here is available on riched.Stream with the same method name but with the return value being the next stream instance which makes it easier to use.

func NewEditor

func NewEditor(t *rich.Text) *Editor

NewEditor properly initializes an Editor instance.

func (*Editor) Apply

func (e *Editor) Apply(ctx changes.Context, c changes.Change) changes.Value

Apply implements changes.Value

func (*Editor) ClearOverrides

func (e *Editor) ClearOverrides() changes.Change

ClearOverrides removes any overrides if present

func (*Editor) CurrentAttributes

func (e *Editor) CurrentAttributes() rich.Attrs

CurrentAttributes returns the attributes at the current selection.

It does not factor in any overrides or remove Embed styles. Use CurrentEffectiveAttributes for that.

func (*Editor) CurrentEffectiveAttributes

func (e *Editor) CurrentEffectiveAttributes() rich.Attrs

CurrentEffectiveAttributes returns the attributes at the current selection.

It factors in any overrides and removes any "Embed" attributes

func (*Editor) InsertString

func (e *Editor) InsertString(s string) changes.Change

InsertString inserts a string at the current selection

func (*Editor) RemoveOverride

func (e *Editor) RemoveOverride(name string) changes.Change

RemoveOverride removes an override

func (*Editor) SetOverride

func (e *Editor) SetOverride(attr rich.Attr) changes.Change

SetOverride update an override that is used for text insertion

A negative override can be created by using NoAttribute{"name"} as the attribute

func (*Editor) SetSelection

func (e *Editor) SetSelection(focus, anchor []interface{}) changes.Change

SetSelection updates selection state

type NoAttribute

type NoAttribute string

NoAttribute specified that a specific attribute should be nullified. This is used with Editor.SetAttribute to specify that the override is actively removing an attribute

The name of the attribute is the underlying string.

func (NoAttribute) Apply

Apply implements changes.Value

func (NoAttribute) Name

func (n NoAttribute) Name() string

Name just returns the underlying string

type Stream

type Stream struct {
	streams.Stream
	*Editor
}

Stream wraps Editor with a stream.

All the mutation methods on Editor are available directly on Stream but with the return value being the new stream instance.

All the other methods of the underlying Editor are also exposed on Stream instances.

Example
package main

import (
	"fmt"

	"github.com/dotchain/dot/x/rich"
	"github.com/dotchain/dot/x/rich/data"
	"github.com/dotchain/dot/x/rich/html"
	"github.com/dotchain/dot/x/rich/riched"
)

func main() {
	s := riched.NewStream(rich.NewText("Hello world", data.FontBold))
	s = s.SetSelection([]interface{}{5}, []interface{}{5})
	s = s.InsertString(" beautiful")
	fmt.Println(html.Format(s.Editor.Text))

}
Output:

<b>Hello beautiful world</b>

func NewStream

func NewStream(r *rich.Text) *Stream

NewStream creates a new stream out of a rich text value

func (*Stream) ClearOverrides

func (s *Stream) ClearOverrides() *Stream

ClearOverrides removes any overrides if present

func (*Stream) InsertString

func (s *Stream) InsertString(text string) *Stream

InsertString inserts a string at the current selection

func (*Stream) Next

func (s *Stream) Next() *Stream

Next returns the next instance in stream or nil if there isn't one

func (*Stream) RemoveOverride

func (s *Stream) RemoveOverride(name string) *Stream

RemoveOverride removes an override

func (*Stream) SetOverride

func (s *Stream) SetOverride(attr rich.Attr) *Stream

SetOverride update an override that is used for text insertion

func (*Stream) SetSelection

func (s *Stream) SetSelection(focus, anchor []interface{}) *Stream

SetSelection updates selection state

Jump to

Keyboard shortcuts

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