This also makes the right arrow behave identically to ^f when inserting
hints. It also adds ctrl+shift+right and ctrl+alt+right for inserting
only one word of the hint.
Signed-off-by: Sebastian <sebastian@sebsite.pw>
---
made/actions.ha | 13 ++++++++++---
made/line.ha | 14 ++++++++++++--
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/made/actions.ha b/made/actions.ha
index ca6ac90..0444d74 100644
--- a/made/actions.ha
+++ b/made/actions.ha
@@ -13,18 +13,25 @@ fn home(s: *state) void = {
};
fn end(s: *state) void = {
- insert_hint(s);
+ insert_hint(s, false);
s.pos = len(s.buf);
};
-fn insert_hint(s: *state) void = {
+fn insert_hint(s: *state, word: bool) void = {
if (s.pos == len(s.buf)) {
if (s.searching) {
clear(s);
s.searching = false;
s.hidx = len(hist(s));
};
- appendstr(s, s.hint);
+ if (word) {
+ let hint = strings::toutf8(s.hint);
+ let idx = nextword(hint, 0);
+ insert(s.buf[s.pos], hint[..idx]...);
+ s.pos += idx;
+ } else {
+ appendstr(s, s.hint);
+ };
};
};
diff --git a/made/line.ha b/made/line.ha
index ec41f85..20a17c1 100644
--- a/made/line.ha
+++ b/made/line.ha
@@ -44,6 +44,8 @@ export fn line(cfg: (*config | str)) (str | void | io::EOF | error) = {
switch (r) {
case '\x01' => // ^a
home(&s);
+ case '\x02' => // ^b
+ prev(&s, false);
case '\x03' => // ^c
if (!s.searching) {
return void;
@@ -62,7 +64,11 @@ export fn line(cfg: (*config | str)) (str | void | io::EOF | error) = {
case '\x05' => // ^e
end(&s);
case '\x06' => // ^f
- insert_hint(&s);
+ if (s.pos == len(s.buf)) {
+ insert_hint(&s, false);
+ } else {
+ next(&s, false);
+ };
case '\x08', '\x7f' => // ^h, backspace
if (s.pos > 0) {
s.pos = prevchr(s.buf, s.pos);
@@ -168,7 +174,11 @@ fn csi(s: *state) (bool | str | error) = {
case 'B' => // down
histmove(s, false);
case 'C' => // right
- next(s, len(buf) != 0);
+ if (s.pos == len(s.buf)) {
+ insert_hint(s, len(buf) != 0);
+ } else {
+ next(s, len(buf) != 0);
+ };
case 'D' => // left
prev(s, len(buf) != 0);
case 'H' => // home
--
2.38.4