aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui/prompt.rs
diff options
context:
space:
mode:
authorCossonLeo2021-11-04 03:26:01 +0000
committerGitHub2021-11-04 03:26:01 +0000
commit39584cbccdb06b528220a13b643416f3fd5dc3c8 (patch)
tree0735dd712198c3b17596db42696c9b427ed0e34d /helix-term/src/ui/prompt.rs
parent70d21a903fef3ec0787c453f369d95e5223a2656 (diff)
Add c-s to pick word under doc cursor to prompt line & search completion (#831)
* Add prompt shourtcut to book Add completions to search Add c-s to pick word under doc cursor to prompt line * limit 20 last items of search completion, update book * Update book/src/keymap.md Co-authored-by: Ivan Tham <pickfire@riseup.net> * limit search completions 200 Co-authored-by: Ivan Tham <pickfire@riseup.net>
Diffstat (limited to 'helix-term/src/ui/prompt.rs')
-rw-r--r--helix-term/src/ui/prompt.rs35
1 files changed, 33 insertions, 2 deletions
diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs
index 853adfc2..c999ba14 100644
--- a/helix-term/src/ui/prompt.rs
+++ b/helix-term/src/ui/prompt.rs
@@ -185,6 +185,11 @@ impl Prompt {
self.exit_selection();
}
+ pub fn insert_str(&mut self, s: &str) {
+ self.line.insert_str(self.cursor, s);
+ self.cursor += s.len();
+ }
+
pub fn move_cursor(&mut self, movement: Movement) {
let pos = self.eval_movement(movement);
self.cursor = pos
@@ -474,6 +479,26 @@ impl Component for Prompt {
(self.callback_fn)(cx, &self.line, PromptEvent::Update);
}
KeyEvent {
+ code: KeyCode::Char('s'),
+ modifiers: KeyModifiers::CONTROL,
+ } => {
+ let (view, doc) = current!(cx.editor);
+ let text = doc.text().slice(..);
+
+ use helix_core::textobject;
+ let range = textobject::textobject_word(
+ text,
+ doc.selection(view.id).primary(),
+ textobject::TextObject::Inside,
+ 1,
+ );
+ let line = text.slice(range.from()..range.to()).to_string();
+ if !line.is_empty() {
+ self.insert_str(line.as_str());
+ (self.callback_fn)(cx, &self.line, PromptEvent::Update);
+ }
+ }
+ KeyEvent {
code: KeyCode::Enter,
..
} => {
@@ -520,11 +545,17 @@ impl Component for Prompt {
}
KeyEvent {
code: KeyCode::Tab, ..
- } => self.change_completion_selection(CompletionDirection::Forward),
+ } => {
+ self.change_completion_selection(CompletionDirection::Forward);
+ (self.callback_fn)(cx, &self.line, PromptEvent::Update)
+ }
KeyEvent {
code: KeyCode::BackTab,
..
- } => self.change_completion_selection(CompletionDirection::Backward),
+ } => {
+ self.change_completion_selection(CompletionDirection::Backward);
+ (self.callback_fn)(cx, &self.line, PromptEvent::Update)
+ }
KeyEvent {
code: KeyCode::Char('q'),
modifiers: KeyModifiers::CONTROL,