Merge pull request #88 from tkurtbond/new-bash-emacs-editing

New bash emacs editing
This commit is contained in:
Nader K. Rad 2025-05-16 18:38:43 +02:00 committed by GitHub
commit 25e23569f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 14 deletions

37
h-m-m
View file

@ -1728,7 +1728,9 @@ function magic_readline(&$mm, $title)
$in==special_keys['arr_up'] ||
$in==special_keys['home_alternative1'] ||
$in==special_keys['home_alternative2'] ||
$in==special_keys['home_alternative3']
$in==special_keys['home_alternative3'] ||
$in==special_keys['ctrl_p'] ||
$in==special_keys['ctrl_a']
)
$cursor = 1;
@ -1737,17 +1739,27 @@ function magic_readline(&$mm, $title)
$in==special_keys['arr_down'] ||
$in==special_keys['end_alternative1'] ||
$in==special_keys['end_alternative2'] ||
$in==special_keys['end_alternative3']
$in==special_keys['end_alternative3'] ||
$in==special_keys['ctrl_n'] ||
$in==special_keys['ctrl_e']
)
$cursor = mb_strlen($title)+1;
elseif ($in==special_keys['arr_right'])
elseif
(
$in==special_keys['arr_right'] ||
$in==special_keys['ctrl_f']
)
$cursor = min( mb_strlen($title)+1, $cursor+1);
elseif ($in==special_keys['arr_left'])
elseif
(
$in==special_keys['arr_left'] ||
$in==special_keys['ctrl_b']
)
$cursor = max(1, $cursor-1);
elseif ($in==special_keys['ctrl_arr_left'] || $in==special_keys['shift_arr_left'] || $in==special_keys['meta_arr_left'])
elseif ($in==special_keys['ctrl_arr_left'] || $in==special_keys['shift_arr_left'] || $in==special_keys['meta_arr_left'] || $in==special_keys['alt_b'])
$cursor =
$cursor < 3
? 1
@ -1761,7 +1773,7 @@ function magic_readline(&$mm, $title)
)
);
elseif ($in==special_keys['ctrl_arr_right'] || $in==special_keys['shift_arr_right'] || $in==special_keys['meta_arr_right'])
elseif ($in==special_keys['ctrl_arr_right'] || $in==special_keys['shift_arr_right'] || $in==special_keys['meta_arr_right'] || $in==special_keys['alt_f'])
$cursor =
$cursor > mb_strlen($title) -2
? mb_strlen($title) + 1
@ -1821,7 +1833,7 @@ function magic_readline(&$mm, $title)
}
}
elseif ($in==special_keys['ctrl_del'])
elseif ($in==special_keys['ctrl_del'] || $in==special_keys['alt_d'])
{
$len = mb_strlen($title);
$from =
@ -1863,6 +1875,17 @@ function magic_readline(&$mm, $title)
elseif ($in==special_keys['enter'])
return trim($title);
elseif ($in==special_keys['ctrl_k'])
{
$title = mb_substr ($title, 0, $cursor-1);
}
elseif ($in==special_keys['ctrl_u'])
{
$title = mb_substr ($title, $cursor-1);
$cursor = 1;
}
elseif ($in==special_keys['ctrl_v'])
{
$content =

View file

@ -94,16 +94,18 @@ Misc:
In the text editor:
* `↓` - moves the cursor to the end of the line
* `↑` - moves the cursor to the beginning of the line
* `←` or `Home` - moves the cursor to the left
* `→` or `End` - moves the cursor to the right
* `Ctrl+Left` or `Shift+Left` - moves cursor to the previous word
* `Ctrl+Right` or `Shift+right` - moves cursor to the next word
* `↓` or `Ctrl-e` or `Ctrl-n` - moves the cursor to the end of the line
* `↑` or `Ctrl-p` or `Ctrl-a` or `Ctrl-p` - moves the cursor to the beginning of the line
* `←` or `Home` or `Ctrl-b` - moves the cursor to the left
* `→` or `End` or `Ctrl-f` - moves the cursor to the right
* `Ctrl+Left` or `Shift+Left` or `Alt-b`- moves cursor to the previous word
* `Ctrl+Right` or `Shift+right`or `Atl-f` - moves cursor to the next word
* `Delete` - deletes character
* `Ctrl+Delete` - deletes word
* `Ctrl+Delete`or `Alt-d` - deletes word
* `Backspace` - deletes previous character
* `ctrl+Backspace`, `ctrl+w` - deletes previous word
* `Ctrl-k` - deletes everything to the right of the cursor
* `Ctrl-u` - deletes everything to the left of the cursor
* `Ctrl+v` or `Ctrl+Shift+v` - paste
* `Esc` - cancels editing
* `Enter` - wanna guess? ;)