aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorDario Oddenino2022-10-28 01:31:28 +0000
committerGitHub2022-10-28 01:31:28 +0000
commit6752c7d3474289596c9e062f54beaf07011b6a40 (patch)
tree3a7860bacd1ad224c5d20788c716223440489d6d /helix-term/src
parentde5b100556ce4d9a2f739bd54904246f97dc6863 (diff)
Trim quotes and braces from paths in goto_file_impl (#4370)
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs23
1 files changed, 17 insertions, 6 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 69870a27..48bd9e57 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1023,6 +1023,7 @@ fn goto_file_vsplit(cx: &mut Context) {
goto_file_impl(cx, Action::VerticalSplit);
}
+/// Goto files in selection.
fn goto_file_impl(cx: &mut Context, action: Action) {
let (view, doc) = current_ref!(cx.editor);
let text = doc.text();
@@ -1032,15 +1033,25 @@ fn goto_file_impl(cx: &mut Context, action: Action) {
.map(|r| text.slice(r.from()..r.to()).to_string())
.collect();
let primary = selections.primary();
- if selections.len() == 1 && primary.to() - primary.from() == 1 {
- let current_word = movement::move_next_long_word_start(
- text.slice(..),
- movement::move_prev_long_word_start(text.slice(..), primary, 1),
- 1,
+ // Checks whether there is only one selection with a width of 1
+ if selections.len() == 1 && primary.len() == 1 {
+ let count = cx.count();
+ let text_slice = text.slice(..);
+ // In this case it selects the WORD under the cursor
+ let current_word = textobject::textobject_word(
+ text_slice,
+ primary,
+ textobject::TextObject::Inside,
+ count,
+ true,
);
+ // Trims some surrounding chars so that the actual file is opened.
+ let surrounding_chars: &[_] = &['\'', '"', '(', ')'];
paths.clear();
paths.push(
- text.slice(current_word.from()..current_word.to())
+ current_word
+ .fragment(text_slice)
+ .trim_matches(surrounding_chars)
.to_string(),
);
}