1
0
зеркало из https://github.com/glebtv/tui-textarea.git synced 2026-09-08 08:25:51 +03:00

add default key maps for scrolling down/up by page

Этот коммит содержится в:
rhysd
2022-10-17 21:54:36 +09:00
родитель 972dfead2d
Коммит eb4103e581
2 изменённых файлов: 70 добавлений и 38 удалений

Просмотреть файл

@@ -175,12 +175,14 @@ Default key mappings are as follows:
| `Ctrl+N`, `↓` | Move cursor down by one line |
| `Alt+F`, `Ctrl+→` | Move cursor forward by word |
| `Atl+B`, `Ctrl+←` | Move cursor backward by word |
| `Alt+P`, `Ctrl+↑` | Move cursor up by paragraph |
| `Alt+N`, `Ctrl+↓` | Move cursor down by paragraph |
| `Alt+]`, `Alt+P`, `Ctrl+↑` | Move cursor up by paragraph |
| `Alt+[`, `Alt+N`, `Ctrl+↓` | Move cursor down by paragraph |
| `Ctrl+E`, `End`, `Ctrl+Alt+F`, `Ctrl+Alt+→` | Move cursor to the end of line |
| `Ctrl+A`, `Home`, `Ctrl+Alt+B`, `Ctrl+Alt+←` | Move cursor to the head of line |
| `Alt+<`, `Ctrl+Alt+P`, `Ctrl+Alt+↑` | Move cursor to top of lines |
| `Alt+>`, `Ctrl+Alt+N`, `Ctrl+Alt+↓` | Move cursor to bottom of lines |
| `Ctrl+V`, `PageDown` | Scroll down by page |
| `Alt+V`, `PageUp` | Scroll up by page |
Deleting multiple characters at once saves the deleted text to yank buffer. It can be pasted with `Ctrl+Y` or `Ctrl+V`
later.
@@ -387,7 +389,7 @@ All editor operations are defined as public methods of `TextArea`. To move curso
notify how to move the cursor.
| Method | Operation |
|------------------------------------------------------|----------------------------------------------|
|------------------------------------------------------|-------------------------------------------------|
| `textarea.delete_char()` | Delete one character before cursor |
| `textarea.delete_next_char()` | Delete one character next to cursor |
| `textarea.insert_newline()` | Insert newline |
@@ -415,7 +417,11 @@ notify how to move the cursor.
| `textarea.set_search_pattern(pattern)` | Set a pattern for text search |
| `textarea.search_forward(match_cursor)` | Move cursor to next match of text search |
| `textarea.search_back(match_cursor)` | Move cursor to previous match of text search |
| `textarea.scroll(scrolling)` | Scroll the viewport |
| `textarea.scroll(Scrolling::PageDown)` | Scroll down the viewport by page |
| `textarea.scroll(Scrolling::PageUp)` | Scroll up the viewport by page |
| `textarea.scroll(Scrolling::HalfPageDown)` | Scroll down the viewport by half-page |
| `textarea.scroll(Scrolling::HalfPageUp)` | Scroll up the viewport by half-page |
| `textarea.scroll((row, col))` | Scroll down the viewport to (row, col) position |
To define your own key mappings, simply call the above methods in your code instead of `TextArea::input()` method. The
following example defines modal key mappings like Vim.

Просмотреть файл

@@ -399,6 +399,11 @@ impl<'a> TextArea<'a> {
false
}
Input {
key: Key::Char(']'),
ctrl: false,
alt: true,
}
| Input {
key: Key::Char('n'),
ctrl: false,
alt: true,
@@ -407,14 +412,16 @@ impl<'a> TextArea<'a> {
key: Key::Down,
ctrl: true,
alt: false,
}
| Input {
key: Key::PageDown, ..
} => {
self.move_cursor(CursorMove::ParagraphForward);
false
}
Input {
key: Key::Char('['),
ctrl: false,
alt: true,
}
| Input {
key: Key::Char('p'),
ctrl: false,
alt: true,
@@ -423,9 +430,6 @@ impl<'a> TextArea<'a> {
key: Key::Up,
ctrl: true,
alt: false,
}
| Input {
key: Key::PageUp, ..
} => {
self.move_cursor(CursorMove::ParagraphBack);
false
@@ -445,6 +449,28 @@ impl<'a> TextArea<'a> {
ctrl: true,
alt: false,
} => self.paste(),
Input {
key: Key::Char('v'),
ctrl: true,
alt: false,
}
| Input {
key: Key::PageDown, ..
} => {
self.scroll(Scrolling::PageDown);
false
}
Input {
key: Key::Char('v'),
ctrl: false,
alt: true,
}
| Input {
key: Key::PageUp, ..
} => {
self.scroll(Scrolling::PageUp);
false
}
Input {
key: Key::MouseScrollDown,
..