diff options
| author | Massimo Mund <masmu@users.noreply.github.com> | 2025-09-05 12:38:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-05 19:38:22 +0900 |
| commit | ae12e94b1f2d0659f9b1b32ae6380a677ca19d68 (patch) | |
| tree | 8bc5f8b74f5d4d9780327e8e6e2560d6dcb44110 /src/terminal.go | |
| parent | 9ed971cc90c9d65def3c52178578e43f29b68f9f (diff) | |
| download | fzf-ae12e94b1f2d0659f9b1b32ae6380a677ca19d68.tar.gz | |
Add sub-word actions (#3997)
Add `backward-subword`, `forward-subword`, `kill-subword`, `backward-kill-subword` actions.
Diffstat (limited to 'src/terminal.go')
| -rw-r--r-- | src/terminal.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/terminal.go b/src/terminal.go index f3f5298b..7e179bea 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -291,6 +291,8 @@ type Terminal struct { gapLineLen int wordRubout string wordNext string + subWordRubout string + subWordNext string cx int cy int offset int @@ -512,6 +514,7 @@ const ( actBackwardDeleteChar actBackwardDeleteCharEof actBackwardWord + actBackwardSubWord actCancel actChangeBorderLabel @@ -541,12 +544,15 @@ const ( actFatal actForwardChar actForwardWord + actForwardSubWord actKillLine actKillWord + actKillSubWord actUnixLineDiscard actUnixWordRubout actYank actBackwardKillWord + actBackwardKillSubWord actSelectAll actDeselectAll actToggle @@ -937,6 +943,8 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor } wordRubout := "[^\\pL\\pN][\\pL\\pN]" wordNext := "[\\pL\\pN][^\\pL\\pN]|(.$)" + subWordRubout := "[a-z][A-Z]|[^\\pL\\pN][\\pL\\pN]" + subWordNext := "[a-z][A-Z]|[\\pL\\pN][^\\pL\\pN]|(.$)" if opts.FileWord { sep := regexp.QuoteMeta(string(os.PathSeparator)) wordRubout = fmt.Sprintf("%s[^%s]", sep, sep) @@ -970,6 +978,8 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor markerMultiLine: *opts.MarkerMulti, wordRubout: wordRubout, wordNext: wordNext, + subWordRubout: subWordRubout, + subWordNext: subWordNext, cx: len(input), cy: 0, offset: 0, @@ -6021,6 +6031,11 @@ func (t *Terminal) Loop() error { if t.cx > 0 { t.rubout(t.wordRubout) } + case actBackwardKillSubWord: + beof = len(t.input) == 0 + if t.cx > 0 { + t.rubout(t.subWordRubout) + } case actYank: suffix := copySlice(t.input[t.cx:]) t.input = append(append(t.input[:t.cx], t.yanked...), suffix...) @@ -6132,6 +6147,10 @@ func (t *Terminal) Loop() error { t.cx = findLastMatch(t.wordRubout, string(t.input[:t.cx])) + 1 case actForwardWord: t.cx += findFirstMatch(t.wordNext, string(t.input[t.cx:])) + 1 + case actBackwardSubWord: + t.cx = findLastMatch(t.subWordRubout, string(t.input[:t.cx])) + 1 + case actForwardSubWord: + t.cx += findFirstMatch(t.subWordNext, string(t.input[t.cx:])) + 1 case actKillWord: ncx := t.cx + findFirstMatch(t.wordNext, string(t.input[t.cx:])) + 1 @@ -6139,6 +6158,13 @@ func (t *Terminal) Loop() error { t.yanked = copySlice(t.input[t.cx:ncx]) t.input = append(t.input[:t.cx], t.input[ncx:]...) } + case actKillSubWord: + ncx := t.cx + + findFirstMatch(t.subWordNext, string(t.input[t.cx:])) + 1 + if ncx > t.cx { + t.yanked = copySlice(t.input[t.cx:ncx]) + t.input = append(t.input[:t.cx], t.input[ncx:]...) + } case actKillLine: if t.cx < len(t.input) { t.yanked = copySlice(t.input[t.cx:]) |
