Compare commits
No commits in common. "e8eaa2366a7443a5727a35d02f0f5b53d9cfe89e" and "bbd23187bc26494b92da49307b3b4aae099d1dae" have entirely different histories.
e8eaa2366a
...
bbd23187bc
62
sdn.cpp
62
sdn.cpp
@ -415,8 +415,7 @@ enum { ALT = 1 << 24, SYM = 1 << 25 }; // Outside the range of Unicode
|
|||||||
XX(CHDIR) XX(PARENT) XX(GO_START) XX(GO_HOME) \
|
XX(CHDIR) XX(PARENT) XX(GO_START) XX(GO_HOME) \
|
||||||
XX(SEARCH) XX(RENAME) XX(RENAME_PREFILL) \
|
XX(SEARCH) XX(RENAME) XX(RENAME_PREFILL) \
|
||||||
XX(TOGGLE_FULL) XX(REVERSE_SORT) XX(SHOW_HIDDEN) XX(REDRAW) XX(RELOAD) \
|
XX(TOGGLE_FULL) XX(REVERSE_SORT) XX(SHOW_HIDDEN) XX(REDRAW) XX(RELOAD) \
|
||||||
XX(INPUT_ABORT) XX(INPUT_CONFIRM) XX(INPUT_B_DELETE) XX(INPUT_DELETE) \
|
XX(INPUT_ABORT) XX(INPUT_CONFIRM) XX(INPUT_B_DELETE)
|
||||||
XX(INPUT_BACKWARD) XX(INPUT_FORWARD) XX(INPUT_BEGINNING) XX(INPUT_END)
|
|
||||||
|
|
||||||
#define XX(name) ACTION_ ## name,
|
#define XX(name) ACTION_ ## name,
|
||||||
enum action { ACTIONS(XX) ACTION_COUNT };
|
enum action { ACTIONS(XX) ACTION_COUNT };
|
||||||
@ -453,11 +452,7 @@ static map<wint_t, action> g_input_actions {
|
|||||||
{L'\r', ACTION_INPUT_CONFIRM}, {KEY (ENTER), ACTION_INPUT_CONFIRM},
|
{L'\r', ACTION_INPUT_CONFIRM}, {KEY (ENTER), ACTION_INPUT_CONFIRM},
|
||||||
// Sometimes terminfo is wrong, we need to accept both of these
|
// Sometimes terminfo is wrong, we need to accept both of these
|
||||||
{L'\b', ACTION_INPUT_B_DELETE}, {CTRL ('?'), ACTION_INPUT_B_DELETE},
|
{L'\b', ACTION_INPUT_B_DELETE}, {CTRL ('?'), ACTION_INPUT_B_DELETE},
|
||||||
{KEY (BACKSPACE), ACTION_INPUT_B_DELETE}, {KEY (DC), ACTION_INPUT_DELETE},
|
{KEY (BACKSPACE), ACTION_INPUT_B_DELETE},
|
||||||
{CTRL ('B'), ACTION_INPUT_BACKWARD}, {KEY (LEFT), ACTION_INPUT_BACKWARD},
|
|
||||||
{CTRL ('F'), ACTION_INPUT_FORWARD}, {KEY (RIGHT), ACTION_INPUT_FORWARD},
|
|
||||||
{CTRL ('A'), ACTION_INPUT_BEGINNING}, {KEY (HOME), ACTION_INPUT_BEGINNING},
|
|
||||||
{CTRL ('E'), ACTION_INPUT_END}, {KEY (END), ACTION_INPUT_END},
|
|
||||||
};
|
};
|
||||||
static const map<string, map<wint_t, action>*> g_binding_contexts {
|
static const map<string, map<wint_t, action>*> g_binding_contexts {
|
||||||
{"normal", &g_normal_actions}, {"input", &g_input_actions},
|
{"normal", &g_normal_actions}, {"input", &g_input_actions},
|
||||||
@ -528,7 +523,6 @@ static struct {
|
|||||||
|
|
||||||
const wchar_t *editor; ///< Prompt string for editing
|
const wchar_t *editor; ///< Prompt string for editing
|
||||||
wstring editor_line; ///< Current user input
|
wstring editor_line; ///< Current user input
|
||||||
int editor_cursor = 0; ///< Cursor position
|
|
||||||
void (*editor_on_change) (); ///< Callback on editor change
|
void (*editor_on_change) (); ///< Callback on editor change
|
||||||
void (*editor_on_confirm) (); ///< Callback on editor confirmation
|
void (*editor_on_confirm) (); ///< Callback on editor confirmation
|
||||||
|
|
||||||
@ -748,11 +742,8 @@ fun update () {
|
|||||||
curs_set (0);
|
curs_set (0);
|
||||||
if (g.editor) {
|
if (g.editor) {
|
||||||
move (LINES - 1, 0);
|
move (LINES - 1, 0);
|
||||||
auto prompt = apply_attrs (wstring (g.editor) + L": ", 0);
|
auto p = apply_attrs (wstring (g.editor) + L": ", 0);
|
||||||
auto line = apply_attrs (g.editor_line, 0);
|
move (LINES - 1, print (p + apply_attrs (g.editor_line, 0), COLS - 1));
|
||||||
print (prompt + line, COLS - 1);
|
|
||||||
auto start = sanitize (prompt + line.substr (0, g.editor_cursor));
|
|
||||||
move (LINES - 1, compute_width (start));
|
|
||||||
curs_set (1);
|
curs_set (1);
|
||||||
} else if (!g.message.empty ()) {
|
} else if (!g.message.empty ()) {
|
||||||
move (LINES - 1, 0);
|
move (LINES - 1, 0);
|
||||||
@ -1184,56 +1175,20 @@ fun handle_editor (wint_t c) {
|
|||||||
g.editor_on_confirm ();
|
g.editor_on_confirm ();
|
||||||
// Fall-through
|
// Fall-through
|
||||||
case ACTION_INPUT_ABORT:
|
case ACTION_INPUT_ABORT:
|
||||||
g.editor = 0;
|
|
||||||
g.editor_line.clear ();
|
g.editor_line.clear ();
|
||||||
g.editor_cursor = 0;
|
g.editor = 0;
|
||||||
g.editor_on_change = nullptr;
|
g.editor_on_change = nullptr;
|
||||||
g.editor_on_confirm = nullptr;
|
g.editor_on_confirm = nullptr;
|
||||||
break;
|
break;
|
||||||
case ACTION_INPUT_BEGINNING:
|
|
||||||
g.editor_cursor = 0;
|
|
||||||
break;
|
|
||||||
case ACTION_INPUT_END:
|
|
||||||
g.editor_cursor = g.editor_line.length ();
|
|
||||||
break;
|
|
||||||
case ACTION_INPUT_BACKWARD:
|
|
||||||
while (g.editor_cursor > 0) {
|
|
||||||
if (--g.editor_cursor <= 0
|
|
||||||
|| wcwidth (g.editor_line.at (g.editor_cursor)))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ACTION_INPUT_FORWARD:
|
|
||||||
while (g.editor_cursor < int (g.editor_line.length ())) {
|
|
||||||
if (++g.editor_cursor >= int (g.editor_line.length ())
|
|
||||||
|| wcwidth (g.editor_line.at (g.editor_cursor)))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ACTION_INPUT_B_DELETE:
|
case ACTION_INPUT_B_DELETE:
|
||||||
// Remove the last character including its postfix combining characters
|
if (!g.editor_line.empty ())
|
||||||
while (g.editor_cursor > 0) {
|
g.editor_line.erase (g.editor_line.length () - 1);
|
||||||
auto erased = g.editor_line.at (--g.editor_cursor);
|
|
||||||
g.editor_line.erase (g.editor_cursor, 1);
|
|
||||||
if (wcwidth (erased))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ACTION_INPUT_DELETE:
|
|
||||||
// Remove the next character including its postfix combining characters
|
|
||||||
while (g.editor_cursor < int (g.editor_line.length ())) {
|
|
||||||
g.editor_line.erase (g.editor_cursor, 1);
|
|
||||||
if (g.editor_cursor >= int (g.editor_line.length ())
|
|
||||||
|| wcwidth (g.editor_line.at (g.editor_cursor)))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (c & (ALT | SYM)) {
|
if (c & (ALT | SYM)) {
|
||||||
beep ();
|
beep ();
|
||||||
} else {
|
} else {
|
||||||
g.editor_line.insert (g.editor_cursor, 1, c);
|
g.editor_line += c;
|
||||||
g.editor_cursor++;
|
|
||||||
if (g.editor_on_change)
|
if (g.editor_on_change)
|
||||||
g.editor_on_change ();
|
g.editor_on_change ();
|
||||||
}
|
}
|
||||||
@ -1357,7 +1312,6 @@ fun handle (wint_t c) -> bool {
|
|||||||
break;
|
break;
|
||||||
case ACTION_RENAME_PREFILL:
|
case ACTION_RENAME_PREFILL:
|
||||||
g.editor_line = to_wide (current.filename);
|
g.editor_line = to_wide (current.filename);
|
||||||
g.editor_cursor = g.editor_line.length ();
|
|
||||||
// Fall-through
|
// Fall-through
|
||||||
case ACTION_RENAME:
|
case ACTION_RENAME:
|
||||||
g.editor = L"rename";
|
g.editor = L"rename";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user