Skip to content
This repository was archived by the owner on Nov 5, 2022. It is now read-only.

textcursor type to replace textselection #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions mixins/code_editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ package mixins

import (
"fmt"
"strings"

"github.com/google/gxui"
"github.com/google/gxui/math"
"strings"
)

type CodeEditorOuter interface {
Expand Down Expand Up @@ -192,7 +193,7 @@ func (t *CodeEditor) KeyPress(ev gxui.KeyboardEvent) (consume bool) {
if t.IsSuggestionListShowing() {
text := t.suggestionAdapter.Suggestion(t.suggestionList.Selected()).Code()
s, e := controller.WordAt(t.controller.LastCaret())
controller.SetSelection(gxui.CreateTextSelection(s, e, false))
controller.SetSelection(gxui.CreateTextCursor(s, e))
controller.ReplaceAll(text)
controller.Deselect(false)
t.HideSuggestionList()
Expand Down
2 changes: 1 addition & 1 deletion mixins/default_textbox_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (t *DefaultTextBoxLine) PaintSelections(c gxui.Canvas) {
if t.textbox.selectionDragging {
interval.Replace(&selections, t.textbox.selectionDrag)
}
interval.Visit(&selections, gxui.CreateTextSelection(ls, le, false), func(s, e uint64, _ int) {
interval.Visit(&selections, gxui.CreateTextCursor(ls, le), func(s, e uint64, _ int) {
if s < e {
x := t.outer.MeasureRunes(ls, int(s)).W
m := t.outer.MeasureRunes(int(s), int(e))
Expand Down
24 changes: 14 additions & 10 deletions mixins/textbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
package mixins

import (
"strings"

"github.com/google/gxui"
"github.com/google/gxui/math"
"github.com/google/gxui/mixins/parts"
"strings"
)

type TextBoxLine interface {
Expand Down Expand Up @@ -36,15 +37,15 @@ type TextBox struct {
controller *gxui.TextBoxController
adapter *TextBoxAdapter
selectionDragging bool
selectionDrag gxui.TextSelection
selectionDrag gxui.TextCursor
desiredWidth int
}

func (t *TextBox) lineMouseDown(line TextBoxLine, ev gxui.MouseEvent) {
if ev.Button == gxui.MouseButtonLeft {
p := line.RuneIndexAt(ev.Point)
t.selectionDragging = true
t.selectionDrag = gxui.CreateTextSelection(p, p, false)
t.selectionDrag = gxui.TextCursor{Index: p}
if !ev.Modifier.Control() {
t.controller.SetCaret(p)
}
Expand Down Expand Up @@ -165,12 +166,14 @@ func (t *TextBox) SetDesiredWidth(desiredWidth int) {
}
}

func (t *TextBox) Select(sel gxui.TextSelectionList) {
func (t *TextBox) Select(sel gxui.TextCursorList) {
t.controller.StoreCaretLocations()
t.controller.SetSelections(sel)
// Use two scroll tos to try and display all selections (if it fits on screen)
t.ScrollToRune(t.controller.FirstSelection().First())
t.ScrollToRune(t.controller.LastSelection().Last())
firstStart, _ := t.controller.FirstSelection().Range()
_, lastEnd := t.controller.LastSelection().Range()
t.ScrollToRune(firstStart)
t.ScrollToRune(lastEnd - 1)
}

func (t *TextBox) SelectAll() {
Expand Down Expand Up @@ -407,11 +410,11 @@ func (t *TextBox) Click(ev gxui.MouseEvent) (consume bool) {

func (t *TextBox) DoubleClick(ev gxui.MouseEvent) (consume bool) {
if p, ok := t.RuneIndexAt(ev.Point); ok {
s, e := t.controller.WordAt(p)
c := gxui.CreateTextCursor(t.controller.WordAt(p))
if ev.Modifier&gxui.ModControl != 0 {
t.controller.AddSelection(gxui.CreateTextSelection(s, e, false))
t.controller.AddSelection(c)
} else {
t.controller.SetSelection(gxui.CreateTextSelection(s, e, false))
t.controller.SetSelection(c)
}
}
t.InputEventHandler.DoubleClick(ev)
Expand All @@ -422,7 +425,8 @@ func (t *TextBox) MouseMove(ev gxui.MouseEvent) {
t.List.MouseMove(ev)
if t.selectionDragging {
if p, ok := t.RuneIndexAt(ev.Point); ok {
t.selectionDrag = gxui.CreateTextSelection(t.selectionDrag.From(), p, false)
idx := t.selectionDrag.Index + t.selectionDrag.Length
t.selectionDrag = gxui.CreateTextCursor(idx, p)
t.selectionDragging = true
t.onRedrawLines.Fire()
}
Expand Down
53 changes: 0 additions & 53 deletions text_selection.go

This file was deleted.

79 changes: 0 additions & 79 deletions text_selection_list.go

This file was deleted.

120 changes: 0 additions & 120 deletions text_selection_list_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion textbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type TextBox interface {
SetDesiredWidth(desiredWidth int)
TextColor() Color
SetTextColor(Color)
Select(TextSelectionList)
Select(TextCursorList)
SelectAll()
Carets() []int
RuneIndexAt(p math.Point) (idx int, found bool)
Expand Down
Loading