Cleanup
This commit is contained in:
parent
e8eaa2366a
commit
706795c85c
33
sdn.cpp
33
sdn.cpp
|
@ -1176,6 +1176,14 @@ fun choose (const entry &entry) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move the cursor in `diff` direction and look for non-combining characters
|
||||||
|
fun move_towards_spacing (int diff) -> bool {
|
||||||
|
g.editor_cursor += diff;
|
||||||
|
return g.editor_cursor <= 0
|
||||||
|
|| g.editor_cursor >= int (g.editor_line.length ())
|
||||||
|
|| wcwidth (g.editor_line.at (g.editor_cursor));
|
||||||
|
}
|
||||||
|
|
||||||
fun handle_editor (wint_t c) {
|
fun handle_editor (wint_t c) {
|
||||||
auto i = g_input_actions.find (c);
|
auto i = g_input_actions.find (c);
|
||||||
switch (i == g_input_actions.end () ? ACTION_NONE : i->second) {
|
switch (i == g_input_actions.end () ? ACTION_NONE : i->second) {
|
||||||
|
@ -1197,34 +1205,27 @@ fun handle_editor (wint_t c) {
|
||||||
g.editor_cursor = g.editor_line.length ();
|
g.editor_cursor = g.editor_line.length ();
|
||||||
break;
|
break;
|
||||||
case ACTION_INPUT_BACKWARD:
|
case ACTION_INPUT_BACKWARD:
|
||||||
while (g.editor_cursor > 0) {
|
while (g.editor_cursor > 0
|
||||||
if (--g.editor_cursor <= 0
|
&& !move_towards_spacing (-1))
|
||||||
|| wcwidth (g.editor_line.at (g.editor_cursor)))
|
;
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case ACTION_INPUT_FORWARD:
|
case ACTION_INPUT_FORWARD:
|
||||||
while (g.editor_cursor < int (g.editor_line.length ())) {
|
while (g.editor_cursor < int (g.editor_line.length ())
|
||||||
if (++g.editor_cursor >= int (g.editor_line.length ())
|
&& !move_towards_spacing (+1))
|
||||||
|| wcwidth (g.editor_line.at (g.editor_cursor)))
|
;
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case ACTION_INPUT_B_DELETE:
|
case ACTION_INPUT_B_DELETE:
|
||||||
// Remove the last character including its postfix combining characters
|
|
||||||
while (g.editor_cursor > 0) {
|
while (g.editor_cursor > 0) {
|
||||||
auto erased = g.editor_line.at (--g.editor_cursor);
|
auto finished = move_towards_spacing (-1);
|
||||||
g.editor_line.erase (g.editor_cursor, 1);
|
g.editor_line.erase (g.editor_cursor, 1);
|
||||||
if (wcwidth (erased))
|
if (finished)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ACTION_INPUT_DELETE:
|
case ACTION_INPUT_DELETE:
|
||||||
// Remove the next character including its postfix combining characters
|
|
||||||
while (g.editor_cursor < int (g.editor_line.length ())) {
|
while (g.editor_cursor < int (g.editor_line.length ())) {
|
||||||
g.editor_line.erase (g.editor_cursor, 1);
|
g.editor_line.erase (g.editor_cursor, 1);
|
||||||
if (g.editor_cursor >= int (g.editor_line.length ())
|
if (move_towards_spacing (0))
|
||||||
|| wcwidth (g.editor_line.at (g.editor_cursor)))
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue