gvcode

package module
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 41 Imported by: 5 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gvcode

Build Status Go Reference

gvcode is a Gio based text editor component for code editing, originally created for Typstify.

Key Features:

  • Uses a PieceTable backed text buffer for efficient text editing.
  • Optimized undo/redo operations with built-in support in the PieceTable, including grouping of related edits (e.g. an IME composition is undone as a single batch).
  • Supports both hard and soft tabs, ensuring alignment with tab stops.
  • Lines can be wrapped or left unwrapped, with horizontal scrolling supported.
  • Syntax highlighting by applying TextMate-style scopes and color schemes, with parent scope fallback.
  • Built-in line numbers for better readability.
  • Extensible gutter system: multiple custom providers, interactive providers (click/hover), and full-width line highlighting.
  • Text markers to track positions and ranges across edits.
  • Text decorations to highlight text using background, underline, squiggle, strikethrough, border, bold and italic styles. Decorations automatically follow text edits.
  • Auto-completion of bracket pairs and quote pairs, including smart skip-over and paired deletion.
  • Auto-indent of new lines.
  • Bracket-aware auto-indent.
  • Increase or decrease indents of selected lines using Tab and Shift+Tab.
  • Highlighting of matching brackets and all occurrences of the word/selection at the caret.
  • Expanded shortcuts support via command registry, with commands that can be registered and removed at runtime.
  • Hooks to intercept paste, Enter/Return and normal text input.
  • Flexible auto-completion via the Completion API, a built-in implementation is provided as an add-on.
  • Add-ons for completion popups and VCS diffs (diff gutter provider and diff popup).
  • Editor modes: normal, read-only and LSP snippet mode.
  • LSP snippet support with tab-stop/placeholder navigation.
  • LF/CRLF line-ending detection and conversion.
  • Indentation detection for tabs vs. spaces and indent width.
  • Large file rendering supported by incremental, paragraph-based rendering.
  • Cross-platform IME support: Windows, macOS, and Linux are supported.
  • Rich configuration options.

Why another code editor?

I ported Gio's editor component to gioview and added a few features to support basic code editing, but it is far from a good code editor. Keep expanding the original editor seems a wise decision, but the design of the original editor makes it hard to adding more features. And it is also not performant enough for large file editing/rendering. Most importantly it lacks tab/tab stop support. When I tried to add tab stop support to it, I found it needs a new overall design, so there is gvcode.

Screenshots

Example editor

How To Use

Gvcode exports simple APIs to ease the integration with your project. Here is a basic example:

package main

import (
	"os"

	"gioui.org/app"
	"gioui.org/font"
	"gioui.org/op"
	"gioui.org/unit"
	"gioui.org/widget/material"
	"github.com/oligo/gvcode"
	"github.com/oligo/gvcode/widget"
)

func main() {
	th := material.NewTheme()

	// widget.NewEditor builds an editor preconfigured with the theme.
	editor := widget.NewEditor(th)
	editor.WithOptions(
		gvcode.WithFont(font.Font{Typeface: "monospace"}),
		gvcode.WithTextSize(unit.Sp(12)),
		gvcode.WithLineHeight(0, 1.5),
	)
	editor.SetText("Hello, gvcode!")

	go func() {
		w := new(app.Window)
		w.Option(app.Title("gvcode example"))

		var ops op.Ops
		for {
			e := w.Event()

			switch e := e.(type) {
			case app.DestroyEvent:
				os.Exit(0)
			case app.FrameEvent:
				gtx := app.NewContext(&ops, e)
				editor.Layout(gtx, th.Shaper)
				e.Frame(gtx.Ops)
			}
		}
	}()

	app.Main()
}

For a full working example, please see code in the folder ./example, or code in Typstify.

For complete API documentations, please read it on Godoc

Cautions

gvcode is not intended to be a drop-in replacement for the official Editor widget as it dropped some features such as single line mode, truncator and max lines limit.

This project is a work in progress, and the APIs may change as development continues. Please use it at your own risk.

Contributing

See the contribution guide for details.

Acknowledgments

This project uses code from the Gio project, which is licensed under the Unlicense OR MIT License.

Documentation

Index

Constants

View Source
const (
	BiasForward  = buffer.BiasForward
	BiasBackward = buffer.BiasBackward
)

Variables

This section is empty.

Functions

func SetDebug added in v0.1.0

func SetDebug(enable bool)

SetDebug enable or disable the debug mode. In debug mode, internal buffer state is printed.

func StripLineEnding added in v0.7.0

func StripLineEnding(text string) string

func ToCRLF added in v0.7.0

func ToCRLF(text string) string

Types

type BeforePasteHook added in v0.1.0

type BeforePasteHook func(text string) string

BeforePasteHook defines a hook to be called before pasting text to transform the text.

type ChangeEvent added in v0.0.2

type ChangeEvent struct{}

A ChangeEvent is generated for every user change to the text.

type CommandHandler added in v0.2.0

type CommandHandler func(gtx layout.Context, evt key.Event) EditorEvent

CommandHandler defines a callback function for the specific key event. It returns an EditorEvent if there is any.

type Completion added in v0.2.0

type Completion interface {
	// AddCompletors adds Completors to Completion. Completors should run independently and return
	// candidates to Completion. A popup is also required to present the cadidates to user.
	AddCompletor(completor Completor, popup CompletionPopup) error

	// OnText update the completion context. If there is no ongoing session, it should start one.
	OnText(ctx CompletionContext)
	// OnConfirm set a callback which is called when the user selected the candidates.
	OnConfirm(idx int)
	// Cancel cancels the current completion session.
	Cancel()
	// IsActive reports if the completion popup is visible.
	IsActive() bool

	// Offset returns the offset used to locate the popup when painting.
	Offset() image.Point
	// Layout layouts the completion selection box as popup near the caret.
	Layout(gtx layout.Context) layout.Dimensions
}

Completion is the main auto-completion interface for the editor. A Completion object schedules flow between the editor, the visual popup widget and completion algorithms(the Completor).

type CompletionCandidate added in v0.2.1

type CompletionCandidate struct {
	// Label is a short text shown to user to indicate
	// what the candicate looks like.
	Label string
	// TextEdit is the real text with range info to be
	// inserted into the editor.
	TextEdit TextEdit
	// A short description of the candicate.
	Description string
	// Kind of the candicate, for example, function,
	// class, keywords etc.
	Kind string
	// TextFormat defines whether the insert text in a completion item
	// should be interpreted as plain text or a snippet. The possible values are
	// PlainText or Snippet.
	TextFormat string

	// A string that should be used when comparing this item with other items. When
	// it's not provided, Label is used.
	SortText string
	// A string that should be used when filtering a set of completion items. When
	// it's not provided, Label is used.
	FilterText string
}

CompletionCandidate are results returned from Completor, to be presented to the user to select from.

type CompletionContext added in v0.2.0

type CompletionContext struct {
	// The last key input.
	Input string
	// // Prefix is the text before the caret.
	// Prefix string
	// // Suffix is the text after the caret.
	// Suffix string
	// Coordinates of the caret. Scroll off will change after we update the position,
	// so we use doc view position instead of viewport position.
	Coords image.Point
	// The position of the caret in line/column and selection range.
	Position Position
}

type CompletionPopup added in v0.2.0

type CompletionPopup interface {
	Layout(gtx layout.Context, items []CompletionCandidate) layout.Dimensions
}

type CompletionTriggerKind added in v0.8.0

type CompletionTriggerKind uint8
const (
	AutoTrigger CompletionTriggerKind = iota
	CharTrigger
	KeyTrigger
)

type Completor added in v0.2.0

type Completor interface {
	// Trigger returns the Trigger object used to detect the input can trigger a completion
	// session.
	Trigger() Trigger

	// Suggest calls the backend completion engine to fetch possible candicates
	// given the completion context. In the case of LSP, it also needs to sync the
	// editor content by calling notification "textDocument/didChange", or "textDocument/didOpen",
	// before calling the "textDocument/completion" method.
	Suggest(ctx CompletionContext) []CompletionCandidate

	// FilterAndRank filters the passed in candidates using the pattern, and then
	// rank the result.
	FilterAndRank(pattern string, candidates []CompletionCandidate) []CompletionCandidate
}

Completor defines a interface that each of the delegated completor must implement.

type EditRange added in v0.2.2

type EditRange struct {
	Start Position
	End   Position
}

type Editor added in v0.0.2

type Editor struct {
	// contains filtered or unexported fields
}

Editor implements an editable and scrollable text area.

func (*Editor) AddDecorations added in v0.3.0

func (e *Editor) AddDecorations(styles ...decoration.Decoration) error

func (*Editor) CaretCoords added in v0.0.2

func (e *Editor) CaretCoords() f32.Point

CaretCoords returns the coordinates of the caret, relative to the editor itself.

func (*Editor) CaretPos added in v0.0.2

func (e *Editor) CaretPos() (line, col int)

CaretPos returns the line & column numbers of the caret.

func (*Editor) ClearDecorations added in v0.3.0

func (e *Editor) ClearDecorations(source string)

func (*Editor) ClearSelection added in v0.0.2

func (e *Editor) ClearSelection()

ClearSelection clears the selection, by setting the selection end equal to the selection start.

func (*Editor) ColorPalette added in v0.3.0

func (e *Editor) ColorPalette() *color.ColorPalette

func (*Editor) ConvertPos added in v0.2.2

func (e *Editor) ConvertPos(line, col int) (runeOff int, pos f32.Point)

ConvertPos convert a line/col position to rune offset and its pixel position relative to the editor itself.

func (*Editor) CreateMarker added in v0.8.2

func (e *Editor) CreateMarker(runeOff int, bias MarkerBias) (*Marker, error)

CreateMarker creates a position-tracking marker at the given rune offset. The marker survives text edits — call marker.Offset() later for the updated position. Returns an error if the rune offset is out of range.

Use BiasForward to have the marker move with inserted text, BiasBackward to keep it anchored.

func (*Editor) Delete added in v0.0.2

func (e *Editor) Delete(graphemeClusters int) (deletedRunes int)

Delete runes from the caret position. The sign of the argument specifies the direction to delete: positive is forward, negative is backward.

If there is a selection, it is deleted and counts as a single grapheme cluster.

func (*Editor) DeleteLine added in v0.1.0

func (e *Editor) DeleteLine() (deletedRunes int)

DeleteLine delete the current line, and place the caret at the start of the next line.

func (*Editor) DetectedLineEnding added in v0.7.0

func (e *Editor) DetectedLineEnding() LineEnding

func (*Editor) GetCompletionContext added in v0.2.0

func (e *Editor) GetCompletionContext() CompletionContext

GetCompletionContext returns a context from the current caret position. This is usually used in the condition of a key triggered completion.

func (*Editor) GetReader added in v0.3.0

func (e *Editor) GetReader() io.ReadSeeker

GetReader returns a io.ReadSeeker to the caller to read the text buffer. This is the preferred way to read from the editor, especially when reading from multiple goroutines.

GetReader does not convert \n to \r\n if the detected lineEnding is \r\n, it's the caller's responsibility to do the convertion.

func (*Editor) GutterManager added in v0.5.0

func (e *Editor) GutterManager() *gutter.Manager

GutterManager returns the editor's gutter manager, if one is configured.

func (*Editor) GutterWidth added in v0.3.0

func (e *Editor) GutterWidth() int

GutterWidth returns the width of the gutter in pixel, which can be used to guide to set the horizontal offset when laying out a horizontal scrollbar.

func (*Editor) Insert added in v0.0.2

func (e *Editor) Insert(s string) (insertedRunes int)

Inert insert text s at the cursor position. If there is a selection, it replace the selection with text s.

func (*Editor) InsertLine added in v0.1.0

func (e *Editor) InsertLine(s string) (insertedRunes int)

InsertLine insert a line of text before the current line, and place the caret at the start of the current line.

This single line insertion is mainly for paste operation after copying/cutting the current line(paragraph) when there is no selection, but it can also used outside of the editor to insert a entire line(paragraph).

func (*Editor) InsertSnippet added in v0.4.0

func (e *Editor) InsertSnippet(body string) (insertedRunes int, err error)

func (*Editor) Layout added in v0.0.2

func (e *Editor) Layout(gtx layout.Context, lt *text.Shaper) layout.Dimensions

func (*Editor) Len added in v0.0.2

func (e *Editor) Len() int

Len is the length of the editor contents, in runes.

func (*Editor) Lines added in v0.4.2

func (e *Editor) Lines() int

Lines returns the total number of rendered logical lines.

func (*Editor) Mode added in v0.4.0

func (e *Editor) Mode() EditorMode

func (*Editor) MoveCaret added in v0.0.2

func (e *Editor) MoveCaret(startDelta, endDelta int)

MoveCaret moves the caret (aka selection start) and the selection end relative to their current positions. Positive distances moves forward, negative distances moves backward. Distances are in grapheme clusters, which closely match what users perceive as "characters" even when the characters are multiple code points long.

func (*Editor) PaintOverlay added in v0.3.0

func (e *Editor) PaintOverlay(gtx layout.Context, position image.Point, w layout.Widget)

PaintOverlay draws a overlay widget over the main editor area.

func (*Editor) PrepareForSave added in v0.7.0

func (e *Editor) PrepareForSave(normalizedContent string) string

A helper method to convert line endings based on previously detected one.

func (*Editor) ReadOnly deprecated added in v0.0.2

func (e *Editor) ReadOnly() bool

Deprecated: use Mode() method please.

func (*Editor) ReadTextBetween added in v0.8.0

func (e *Editor) ReadTextBetween(start, end int) string

ReadTextBetween reads text between two rune offsets (start inclusive, end exclusive).

func (*Editor) ReadUntil added in v0.2.2

func (e *Editor) ReadUntil(direction int, seperator func(r rune) bool) string

ReadUntil reads in the specified direction from the current caret position until the seperator returns false. It returns the read text.

func (*Editor) RegisterCommand added in v0.2.0

func (e *Editor) RegisterCommand(srcTag any, filter key.Filter, handler CommandHandler)

RegisterCommand register an extra command handler responding to key events. If there is an existing handler, it appends to the existing ones. Only the last key filter is checked during event handling. This method is expected to be invoked dynamically during layout.

func (*Editor) RemoveCommands added in v0.2.0

func (e *Editor) RemoveCommands(tag any)

RemoveCommands unregister command handlers from tag.

func (*Editor) RemoveMarker added in v0.8.2

func (e *Editor) RemoveMarker(marker *Marker)

RemoveMarker removes a previously created marker, releasing its resources.

func (*Editor) ReplaceAll added in v0.0.2

func (e *Editor) ReplaceAll(texts []TextRange, newStr string) int

ReplaceAll replaces all texts specifed in TextRange with newStr. It returns the number of occurrences replaced.

func (*Editor) Scroll added in v0.3.0

func (e *Editor) Scroll(gtx layout.Context, xRatio, yRatio float32)

Scroll scrolls the horizontal or vertical scrollbar, using ratio related to the rendered document size.

func (*Editor) ScrollRatio added in v0.3.0

func (e *Editor) ScrollRatio() (minX, maxX float32, minY, maxY float32)

ScrollRatio returns the viewport's start and end scrolling offset in ratio relating to the reandered document coordinate space.

func (*Editor) SelectLines added in v0.6.0

func (e *Editor) SelectLines(totalLines int, backward bool)

SelectLines select logical lines starting from the current line(inclusive). The number of lines to be selected is specified by totalLines. If backward is true, it select lines backward.

func (*Editor) SelectedText added in v0.0.2

func (e *Editor) SelectedText() string

SelectedText returns the currently selected text (if any) from the editor.

func (*Editor) Selection added in v0.0.2

func (e *Editor) Selection() (start, end int)

Selection returns the start and end of the selection, as rune offsets. start can be > end.

func (*Editor) SelectionLen added in v0.0.2

func (e *Editor) SelectionLen() int

SelectionLen returns the length of the selection, in runes; it is equivalent to utf8.RuneCountInString(e.SelectedText()).

func (*Editor) SetCaret added in v0.0.2

func (e *Editor) SetCaret(start, end int)

SetCaret moves the caret to start, and sets the selection end to end. start and end are in runes, and represent offsets into the editor text.

func (*Editor) SetSyntaxTokens added in v0.3.0

func (e *Editor) SetSyntaxTokens(tokens ...syntax.Token)

func (*Editor) SetText added in v0.0.2

func (e *Editor) SetText(s string)

SetText init the editor with content s. It also detects the content indent kind, indent size, and the line ending style. Internally the editor uses \n for line ending, so it also convert all \r\n to \n before populate the internal text buffer.

func (*Editor) TabStyle added in v0.1.1

func (e *Editor) TabStyle() (TabStyle, int)

func (*Editor) Text added in v0.0.2

func (e *Editor) Text() string

Text returns the contents of the editor. This method is not concurrent safe, and you should use the Reader returned from GetReader to read from multiple goroutines.

Text does not convert \n to \r\n if the detected lineEnding is \r\n, it's the caller's responsibility to do the convertion.

func (*Editor) TextView added in v0.8.2

func (e *Editor) TextView() *textview.TextView

TextView returns the underlying text view for advanced text manipulation.

func (*Editor) Update added in v0.0.2

func (e *Editor) Update(gtx layout.Context) (EditorEvent, bool)

Update the state of the editor in response to input events. Update consumes editor input events until there are no remaining events or an editor event is generated. To fully update the state of the editor, callers should call Update until it returns false.

func (*Editor) WithOptions added in v0.1.0

func (e *Editor) WithOptions(opts ...EditorOption)

WithOptions applies various options to configure the editor.

type EditorEvent added in v0.0.2

type EditorEvent interface {
	// contains filtered or unexported methods
}

type EditorMode added in v0.4.0

type EditorMode uint8

Mode defines a mode for the editor. The editor can be switched back and forth bewteen different modes, depending on the context.

const (
	// ModeNormal is the default mode for the editor. Users can
	// insert or select text or anything else.
	ModeNormal EditorMode = iota

	// ModeReadOnly controls whether the contents of the editor can be
	// altered by user interaction. If set, the editor will allow selecting
	// text and copying it interactively, but not modifying it. Users can
	// enter or quit this mode via user commands.
	ModeReadOnly

	// ModeSnippet put the editor into the snippet mode required by LSP protocol.
	// The users can navigate bewteen the snippet locations/placeholders using
	// the tab/shift-tab keys. And clicking or pressing the ESC key switched the
	// editor to normal mode.
	//
	// See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#snippet_syntax.
	ModeSnippet
)

type EditorOption added in v0.1.0

type EditorOption func(*Editor)

EditorOption defines a function to configure the editor.

func AddBeforePasteHook added in v0.1.0

func AddBeforePasteHook(hook BeforePasteHook) EditorOption

AddBeforePasteHook registers a hook to transform the pasted text.

func AddEnterHook added in v0.8.2

func AddEnterHook(hook EnterHook) EditorOption

AddEnterHook registers a hook to add custom logic which is called when a Enter/Return is pressed.

func AddTextInputHook added in v0.8.2

func AddTextInputHook(hook TextInputHook) EditorOption

AddTextInputHook registers a hook to add custom logic which is called when normal text character is typed.

func ReadOnlyMode added in v0.1.0

func ReadOnlyMode(enabled bool) EditorOption

ReadOnlyMode controls whether the contents of the editor can be altered by user interaction. If set to true, the editor will allow selecting text and copying it interactively, but not modifying it.

func WithAutoCompletion added in v0.2.0

func WithAutoCompletion(completor Completion) EditorOption

func WithBracketPairs added in v0.1.1

func WithBracketPairs(bracketPairs map[rune]rune) EditorOption

WithBracketPairs configures a set of bracket pairs that can be auto-completed when the left half is entered.

func WithColorScheme added in v0.3.0

func WithColorScheme(scheme syntax.ColorScheme) EditorOption

WithColorScheme configures the color scheme used for styling syntax tokens. Syntax highlight implementations should align with the token types used in the ColorScheme.

func WithCornerRadius added in v0.5.0

func WithCornerRadius(radius unit.Dp) EditorOption

Set a radis value for the corners of selection polygons or borders of other shapes.

func WithDefaultGutters added in v0.5.0

func WithDefaultGutters() EditorOption

WithDefaultGutters enables line numbers via the new gutter system. This is the recommended way to enable line numbers for new code.

func WithFont added in v0.3.0

func WithFont(font font.Font) EditorOption

Set font to use for the editor.

func WithGutter added in v0.5.0

func WithGutter(provider gutter.GutterProvider) EditorOption

WithGutter adds a gutter provider to the editor. Creates a gutter manager if needed. Multiple providers can be added by calling this function multiple times.

func WithGutterGap added in v0.5.0

func WithGutterGap(gap unit.Dp) EditorOption

func WithLineHeight added in v0.3.0

func WithLineHeight(lineHeight unit.Sp, lineHeightScale float32) EditorOption

func WithLineNumber deprecated added in v0.3.0

func WithLineNumber(enabled bool) EditorOption

Deprecated: Please use WithGutter or WithDefaultGutters WithLineNumber configures whether to show line number or not.

func WithQuotePairs added in v0.1.1

func WithQuotePairs(quotePairs map[rune]rune) EditorOption

WithQuotePairs configures a set of quote pairs that can be auto-completed when the left half is entered.

func WithSoftTab added in v0.1.0

func WithSoftTab(enabled bool) EditorOption

WithSoftTab controls the behaviour when user try to insert a Tab character. If set to true, the editor will insert the amount of space characters specified by TabWidth, else the editor insert a \t character.

func WithTabWidth added in v0.1.0

func WithTabWidth(tabWidth int) EditorOption

WithTabWidth set how many spaces to represent a tab character. In the case of soft tab, this determines the number of space characters to insert into the editor. While for hard tab, this controls the maximum width of the 'tab' glyph to expand to.

func WithTextAlignment added in v0.3.0

func WithTextAlignment(align text.Alignment) EditorOption

func WithTextSize added in v0.3.0

func WithTextSize(textSize unit.Sp) EditorOption

Set size of the text.

func WithWordSeperators added in v0.1.0

func WithWordSeperators(seperators string) EditorOption

WithWordSeperators configures a set of characters that will be used as word separators when doing word related operations, like navigating or deleting by word.

func WrapLine added in v0.1.0

func WrapLine(enabled bool) EditorOption

WrapLine configures whether the displayed text will be broken into lines or not.

type EnterHook added in v0.8.2

type EnterHook func(ed *Editor) bool

EnterHook is called when Enter/Return is pressed. Return true to skip the default behavior. The hook receives the Editor and should mutate it directly

type GutterEventWrapper added in v0.5.0

type GutterEventWrapper struct {
	Event gutter.GutterEvent
}

gutterEventWrapper wraps gutter events to implement EditorEvent.

type HoverEvent added in v0.3.0

type HoverEvent struct {
	PixelOff image.Point
	Pos      Position
	IsCancel bool
}

A HoverEvent is generated if the pointer hovers and keep still or maybe some small movement for some time.

type LineEnding added in v0.7.0

type LineEnding string
const (
	LF   LineEnding = "\n"
	CRLF LineEnding = "\r\n"
)

func DetectLineEnding added in v0.7.0

func DetectLineEnding(text string) LineEnding

DetectLineEnding intelligently determines the line ending convention. It scans the whole file for the most common ending if small, otherwise it sniffs the first 4KB for the first occurrence.

type Marker added in v0.8.2

type Marker = buffer.Marker

Re-export internal marker types for public use. These are transparent type aliases for buffer.Marker.

type MarkerBias added in v0.8.2

type MarkerBias = buffer.MarkerBias

Re-export internal marker types for public use. These are transparent type aliases for buffer.Marker.

type Position added in v0.2.2

type Position struct {
	// Line number of the caret where the typing is happening.
	Line int
	// Column is the rune offset from the start of the line.
	Column int
	// Runes is the rune offset in the editor text of the input.
	Runes int
}

Position is a position in the eidtor. Line/column and Runes may not be set at the same time depending on the use cases.

type SelectEvent added in v0.0.2

type SelectEvent struct{}

A SelectEvent is generated when the user selects some text, or changes the selection (e.g. with a shift-click), including if they remove the selection. The selected text is not part of the event, on the theory that it could be a relatively expensive operation (for a large editor), most applications won't actually care about it, and those that do can call Editor.SelectedText() (which can be empty).

type TabStyle added in v0.1.1

type TabStyle uint8
const (
	Tabs TabStyle = iota
	Spaces
)

func GuessIndentation added in v0.1.1

func GuessIndentation(text string) (TabStyle, bool, int)

GuessIndentation guesses which kind of indentation the editor is using, returing the kind, if mixed indent is used, and the indent size in the case if spaces indentation.

type TextEdit added in v0.2.2

type TextEdit struct {
	NewText   string
	EditRange EditRange
}

TextEdit is the text with range info to be inserted into the editor, used in auto-completion.

func NewTextEditWithPos added in v0.2.2

func NewTextEditWithPos(text string, start Position, end Position) TextEdit

func NewTextEditWithRuneOffset added in v0.2.2

func NewTextEditWithRuneOffset(text string, start, end int) TextEdit

type TextInputHook added in v0.8.2

type TextInputHook func(ed *Editor, ke key.EditEvent) bool

TextInputHook is called before text input processing. ke is the input event containing the character and replacement range. Return true to skip the default processing.

The hook receives the Editor so it can read context and insert text.

type TextRange added in v0.0.2

type TextRange struct {
	// offset of the start rune in the document.
	Start int
	// offset of the end rune in the document.
	End int
}

TextRange contains the range of text of interest in the document. It can used for search, styling text, or any other purposes.

type Trigger added in v0.2.0

type Trigger struct {
	// Characters that may start completion under the default policy.
	Characters []string

	// Policy controls completion session activation and prefix handling. When
	// nil, the default completion policy is used.
	Policy TriggerPolicy

	// Trigger completion even the caret is in side of comment.
	Comment bool
	// Trigger completion even the caret is in side of string(quote pair).
	String bool

	// Special key binding triggers the completion.
	KeyBinding struct {
		Name      key.Name
		Modifiers key.Modifiers
	}
}

Trigger

func (Trigger) ActivateOnKey added in v0.2.2

func (tr Trigger) ActivateOnKey(evt key.Event) bool

type TriggerPolicy added in v0.8.0

type TriggerPolicy interface {
	CanStart(trigger Trigger, ctx CompletionContext) bool
	PrefixRange(trigger Trigger, kind CompletionTriggerKind, ctx CompletionContext) EditRange
	ShouldCancel(trigger Trigger, kind CompletionTriggerKind, triggerInput string, ctx CompletionContext, prefix string) bool
}

TriggerPolicy controls how a completion session starts, where its filtering prefix begins, and when the active session should be canceled.

Directories

Path Synopsis
addons
internal
gesture/fling
This package is copied from Gio internal fling package: https://github.com/gioui/gio/tree/main/internal/fling.
This package is copied from Gio internal fling package: https://github.com/gioui/gio/tree/main/internal/fling.
stroke
Package stroke converts complex strokes to gioui.org/op/clip operations.
Package stroke converts complex strokes to gioui.org/op/clip operations.
textstyle

Jump to

Keyboard shortcuts

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