mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-08 10:55:35 +00:00
widget: replace Editor.makeValidCaret
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+5
-13
@@ -223,12 +223,13 @@ func (e *Editor) processEvents(gtx layout.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Editor) makeValid(positions ...*combinedPos) {
|
func (e *Editor) makeValid() {
|
||||||
if e.valid {
|
if e.valid {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
e.lines, e.dims = e.layoutText(e.shaper)
|
e.lines, e.dims = e.layoutText(e.shaper)
|
||||||
e.makeValidCaret(positions...)
|
e.caret.start = e.closestPosition(combinedPos{runes: e.caret.start.runes})
|
||||||
|
e.caret.end = e.closestPosition(combinedPos{runes: e.caret.end.runes})
|
||||||
e.valid = true
|
e.valid = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1119,21 +1120,12 @@ func (e *Editor) Selection() (start, end int) {
|
|||||||
// and end are in runes, and represent offsets into the editor text.
|
// and end are in runes, and represent offsets into the editor text.
|
||||||
func (e *Editor) SetCaret(start, end int) {
|
func (e *Editor) SetCaret(start, end int) {
|
||||||
e.makeValid()
|
e.makeValid()
|
||||||
e.caret.start.runes, e.caret.end.runes = start, end
|
e.caret.start = e.closestPosition(combinedPos{runes: start})
|
||||||
e.makeValidCaret()
|
e.caret.end = e.closestPosition(combinedPos{runes: end})
|
||||||
e.caret.scroll = true
|
e.caret.scroll = true
|
||||||
e.scroller.Stop()
|
e.scroller.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Editor) makeValidCaret(positions ...*combinedPos) {
|
|
||||||
// Jump through some hoops to order the offsets given to offsetToScreenPos,
|
|
||||||
// but still be able to update them correctly with the results thereof.
|
|
||||||
positions = append(positions, &e.caret.start, &e.caret.end)
|
|
||||||
for _, cp := range positions {
|
|
||||||
*cp = e.closestPosition(combinedPos{runes: cp.runes})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SelectedText returns the currently selected text (if any) from the editor.
|
// SelectedText returns the currently selected text (if any) from the editor.
|
||||||
func (e *Editor) SelectedText() string {
|
func (e *Editor) SelectedText() string {
|
||||||
start := min(e.caret.start.ofs, e.caret.end.ofs)
|
start := min(e.caret.start.ofs, e.caret.end.ofs)
|
||||||
|
|||||||
Reference in New Issue
Block a user