mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-19 08:32:48 +08:00
Also trim trailing newlines when adding to history
When pasting and executing a full line, the trailing newline character will be included in history. I usually manually delete the newline before executing, but sometimes I forget. When I recall my (typically single-line) commands, it's surprising that the cursor is on the blank second line. The newline doesn't seem useful. Let's remove it automagically. I wonder if anyone will be thrown off by this smart behavior. In future, we can make this space trimming configurable, similar to fish_should_add_to_history.
This commit is contained in:
parent
081c3282b7
commit
6f480d1d85
|
@ -5722,7 +5722,10 @@ impl<'a> Reader<'a> {
|
||||||
|
|
||||||
// Historical behavior is to trim trailing spaces, unless escape (#7661).
|
// Historical behavior is to trim trailing spaces, unless escape (#7661).
|
||||||
let mut text = self.command_line.text().to_owned();
|
let mut text = self.command_line.text().to_owned();
|
||||||
while text.chars().next_back() == Some(' ')
|
while text
|
||||||
|
.chars()
|
||||||
|
.next_back()
|
||||||
|
.is_some_and(|c| matches!(c, ' ' | '\n'))
|
||||||
&& count_preceding_backslashes(&text, text.len() - 1) % 2 == 0
|
&& count_preceding_backslashes(&text, text.len() - 1) % 2 == 0
|
||||||
{
|
{
|
||||||
text.pop();
|
text.pop();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user