Documentation ¶
Index ¶
- type Editor
- func (e *Editor) Apply(ctx changes.Context, c changes.Change) changes.Value
- func (e *Editor) ClearOverrides() changes.Change
- func (e *Editor) CurrentAttributes() rich.Attrs
- func (e *Editor) CurrentEffectiveAttributes() rich.Attrs
- func (e *Editor) InsertString(s string) changes.Change
- func (e *Editor) RemoveOverride(name string) changes.Change
- func (e *Editor) SetOverride(attr rich.Attr) changes.Change
- func (e *Editor) SetSelection(focus, anchor []interface{}) changes.Change
- type NoAttribute
- type Stream
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Editor ¶
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 (*Editor) ClearOverrides ¶
ClearOverrides removes any overrides if present
func (*Editor) CurrentAttributes ¶
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 ¶
CurrentEffectiveAttributes returns the attributes at the current selection.
It factors in any overrides and removes any "Embed" attributes
func (*Editor) InsertString ¶
InsertString inserts a string at the current selection
func (*Editor) RemoveOverride ¶
RemoveOverride removes an override
func (*Editor) SetOverride ¶
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 ¶
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) Name ¶
func (n NoAttribute) Name() string
Name just returns the underlying string
type Stream ¶
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 (*Stream) ClearOverrides ¶
ClearOverrides removes any overrides if present
func (*Stream) InsertString ¶
InsertString inserts a string at the current selection
func (*Stream) RemoveOverride ¶
RemoveOverride removes an override
func (*Stream) SetOverride ¶
SetOverride update an override that is used for text insertion
func (*Stream) SetSelection ¶
SetSelection updates selection state