allow configuring smart tab to always trigger completion instead

pull/10537/head
Jesse Luehrs 7 months ago
parent 35b6aef5fb
commit 2cb1462005

@ -3759,7 +3759,7 @@ pub mod insert {
}
use helix_core::auto_pairs;
use helix_view::editor::SmartTabConfig;
use helix_view::editor::{SmartTabConfig, SmartTabMode};
pub fn insert_char(cx: &mut Context, c: char) {
let (view, doc) = current_ref!(cx.editor);
@ -3784,10 +3784,10 @@ pub mod insert {
let (view, doc) = current_ref!(cx.editor);
let view_id = view.id;
if matches!(
cx.editor.config().smart_tab,
Some(SmartTabConfig { enable: true, .. })
) {
if let Some(SmartTabConfig {
enable: true, mode, ..
}) = &cx.editor.config().smart_tab
{
let cursors_after_whitespace = doc.selection(view_id).ranges().iter().all(|range| {
let cursor = range.cursor(doc.text().slice(..));
let current_line_num = doc.text().char_to_line(cursor);
@ -3797,7 +3797,10 @@ pub mod insert {
});
if !cursors_after_whitespace {
move_parent_node_end(cx);
match mode {
SmartTabMode::MoveParentNodeEnd => move_parent_node_end(cx),
SmartTabMode::Completion => completion(cx),
}
return;
}
}

@ -13,6 +13,7 @@ use helix_lsp::lsp;
use helix_lsp::util::pos_to_lsp_pos;
use helix_stdx::rope::RopeSliceExt;
use helix_view::document::{Mode, SavePoint};
use helix_view::editor::{SmartTabConfig, SmartTabMode};
use helix_view::handlers::lsp::CompletionEvent;
use helix_view::{DocumentId, Editor, ViewId};
use tokio::sync::mpsc::Sender;
@ -415,6 +416,20 @@ fn completion_post_command_hook(
name: "delete_char_backward",
..
} => update_completions(cx, None),
MappableCommand::Static {
name: "smart_tab", ..
} => {
if !matches!(
cx.editor.config().smart_tab,
Some(SmartTabConfig {
enable: true,
mode: SmartTabMode::Completion,
..
})
) {
clear_completions(cx)
}
}
_ => clear_completions(cx),
}
} else {
@ -438,6 +453,22 @@ fn completion_post_command_hook(
name: "completion" | "insert_mode" | "append_mode",
..
} => return Ok(()),
MappableCommand::Static {
name: "smart_tab", ..
} => {
if matches!(
cx.editor.config().smart_tab,
Some(SmartTabConfig {
enable: true,
mode: SmartTabMode::Completion,
..
})
) {
return Ok(());
} else {
CompletionEvent::Cancel
}
}
_ => CompletionEvent::Cancel,
};
send_blocking(tx, event);

@ -274,6 +274,7 @@ impl<T: Item + 'static> Component for Menu<T> {
Some(SmartTabConfig {
enable: true,
supersede_menu: true,
..
})
)
{

@ -343,6 +343,7 @@ pub struct Config {
pub struct SmartTabConfig {
pub enable: bool,
pub supersede_menu: bool,
pub mode: SmartTabMode,
}
impl Default for SmartTabConfig {
@ -350,10 +351,18 @@ impl Default for SmartTabConfig {
SmartTabConfig {
enable: true,
supersede_menu: false,
mode: SmartTabMode::MoveParentNodeEnd,
}
}
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq, PartialOrd, Ord)]
#[serde(rename_all = "kebab-case")]
pub enum SmartTabMode {
MoveParentNodeEnd,
Completion,
}
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default, rename_all = "kebab-case", deny_unknown_fields)]
pub struct TerminalConfig {

Loading…
Cancel
Save