Skip to content

Commit

Permalink
Update values even if string_difference empty
Browse files Browse the repository at this point in the history
  • Loading branch information
ysthakur committed Jan 5, 2024
1 parent 8e3fb44 commit 65d0d5a
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/menu/columnar_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,29 +526,31 @@ impl Menu for ColumnarMenu {

/// Updates menu values
fn update_values(&mut self, editor: &mut Editor, completer: &mut dyn Completer) {
if self.only_buffer_difference {
self.values = if self.only_buffer_difference {
if let Some(old_string) = &self.input {
let (start, input) = string_difference(editor.get_buffer(), old_string);
if !input.is_empty() {
self.values = completer.complete(input, start + input.len());
self.reset_position();
completer.complete(input, start + input.len())

Check warning on line 533 in src/menu/columnar_menu.rs

View check run for this annotation

Codecov / codecov/patch

src/menu/columnar_menu.rs#L533

Added line #L533 was not covered by tests
} else {
completer.complete("", editor.insertion_point())

Check warning on line 535 in src/menu/columnar_menu.rs

View check run for this annotation

Codecov / codecov/patch

src/menu/columnar_menu.rs#L535

Added line #L535 was not covered by tests
}
} else {
self.values = completer.complete("", editor.insertion_point());
completer.complete("", editor.insertion_point())

Check warning on line 538 in src/menu/columnar_menu.rs

View check run for this annotation

Codecov / codecov/patch

src/menu/columnar_menu.rs#L538

Added line #L538 was not covered by tests
}
} else {
// If there is a new line character in the line buffer, the completer
// doesn't calculate the suggested values correctly. This happens when
// editing a multiline buffer.
// Also, by replacing the new line character with a space, the insert
// Also, by replacing the new line character with a space, the insertF
// position is maintain in the line buffer.
let trimmed_buffer = editor.get_buffer().replace('\n', " ");
self.values = completer.complete(
completer.complete(
&trimmed_buffer[..editor.insertion_point()],
editor.insertion_point(),
);
self.reset_position();
}
)
};

self.reset_position();
}

/// The working details for the menu changes based on the size of the lines
Expand Down

0 comments on commit 65d0d5a

Please sign in to comment.