Skip to content

Instantly share code, notes, and snippets.

@Kvaz1r
Last active December 3, 2017 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kvaz1r/d55c0a9bc6348ed0c5a28ef1a91589de to your computer and use it in GitHub Desktop.
Save Kvaz1r/d55c0a9bc6348ed0c5a28ef1a91589de to your computer and use it in GitHub Desktop.
case gxui.KeyBackspace, gxui.KeyDelete:
var edits []input.Edit
selections := editor.Controller().Selections()
for _, s := range selections {
if s.Start() < 0 {
continue
}
edit := input.Edit{
At: s.Start(),
Old: ctrl.TextRunes()[s.Start():s.End()],
}
if s.Start() == s.End() {
if ev.Key == gxui.KeyBackspace {
if edit.At == 0 {
continue
}
edit.At--
}
edit.Old = ctrl.TextRunes()[edit.At : edit.At+1]
}
edits = append(edits, edit)
}
if len(selections) == 1 && selections[0].Start() >= 0 {
pos := selections[0].Start()
e.Apply(focused, edits...)
editor.Controller().SetCaret(pos)
editor.List.SetScrollOffset(editor.StartOffset())
} else {
e.Apply(focused, edits...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment