mirror of
https://github.com/helix-editor/helix.git
synced 2025-01-19 05:27:07 +04:00
Add :update
that will write the changes if the file has been modified. (#4426)
* add command update that will write the changes if file hasn been modified * add docs * update the docs
This commit is contained in:
parent
65edf9c198
commit
ba9e50e93b
@ -44,6 +44,7 @@
|
|||||||
| `:show-directory`, `:pwd` | Show the current working directory. |
|
| `:show-directory`, `:pwd` | Show the current working directory. |
|
||||||
| `:encoding` | Set encoding. Based on `https://encoding.spec.whatwg.org`. |
|
| `:encoding` | Set encoding. Based on `https://encoding.spec.whatwg.org`. |
|
||||||
| `:reload` | Discard changes and reload from the source file. |
|
| `:reload` | Discard changes and reload from the source file. |
|
||||||
|
| `:update` | Write changes only if the file has been modified. |
|
||||||
| `:lsp-restart` | Restarts the Language Server that is in use by the current doc |
|
| `:lsp-restart` | Restarts the Language Server that is in use by the current doc |
|
||||||
| `:tree-sitter-scopes` | Display tree sitter scopes, primarily for theming and development. |
|
| `:tree-sitter-scopes` | Display tree sitter scopes, primarily for theming and development. |
|
||||||
| `:debug-start`, `:dbg` | Start a debug session from a given template with given parameters. |
|
| `:debug-start`, `:dbg` | Start a debug session from a given template with given parameters. |
|
||||||
|
@ -1029,6 +1029,24 @@ fn reload(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update the [`Document`] if it has been modified.
|
||||||
|
fn update(
|
||||||
|
cx: &mut compositor::Context,
|
||||||
|
args: &[Cow<str>],
|
||||||
|
event: PromptEvent,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
if event != PromptEvent::Validate {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let (_view, doc) = current!(cx.editor);
|
||||||
|
if doc.is_modified() {
|
||||||
|
write(cx, args, event)
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn lsp_restart(
|
fn lsp_restart(
|
||||||
cx: &mut compositor::Context,
|
cx: &mut compositor::Context,
|
||||||
_args: &[Cow<str>],
|
_args: &[Cow<str>],
|
||||||
@ -1957,6 +1975,13 @@ fn run_shell_command(
|
|||||||
fun: reload,
|
fun: reload,
|
||||||
completer: None,
|
completer: None,
|
||||||
},
|
},
|
||||||
|
TypableCommand {
|
||||||
|
name: "update",
|
||||||
|
aliases: &[],
|
||||||
|
doc: "Write changes only if the file has been modified.",
|
||||||
|
fun: update,
|
||||||
|
completer: None,
|
||||||
|
},
|
||||||
TypableCommand {
|
TypableCommand {
|
||||||
name: "lsp-restart",
|
name: "lsp-restart",
|
||||||
aliases: &[],
|
aliases: &[],
|
||||||
|
Loading…
Reference in New Issue
Block a user