File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 44
44
| ` :show-directory ` , ` :pwd ` | Show the current working directory. |
45
45
| ` :encoding ` | Set encoding. Based on ` https://encoding.spec.whatwg.org ` . |
46
46
| ` :reload ` | Discard changes and reload from the source file. |
47
+ | ` :update ` | Write changes only if the file has been modified. |
47
48
| ` :lsp-restart ` | Restarts the Language Server that is in use by the current doc |
48
49
| ` :tree-sitter-scopes ` | Display tree sitter scopes, primarily for theming and development. |
49
50
| ` :debug-start ` , ` :dbg ` | Start a debug session from a given template with given parameters. |
Original file line number Diff line number Diff line change @@ -1029,6 +1029,24 @@ fn reload(
1029
1029
} )
1030
1030
}
1031
1031
1032
+ /// Update the [`Document`] if it has been modified.
1033
+ fn update (
1034
+ cx : & mut compositor:: Context ,
1035
+ args : & [ Cow < str > ] ,
1036
+ event : PromptEvent ,
1037
+ ) -> anyhow:: Result < ( ) > {
1038
+ if event != PromptEvent :: Validate {
1039
+ return Ok ( ( ) ) ;
1040
+ }
1041
+
1042
+ let ( _view, doc) = current ! ( cx. editor) ;
1043
+ if doc. is_modified ( ) {
1044
+ write ( cx, args, event)
1045
+ } else {
1046
+ Ok ( ( ) )
1047
+ }
1048
+ }
1049
+
1032
1050
fn lsp_restart (
1033
1051
cx : & mut compositor:: Context ,
1034
1052
_args : & [ Cow < str > ] ,
@@ -1957,6 +1975,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
1957
1975
fun : reload,
1958
1976
completer : None ,
1959
1977
} ,
1978
+ TypableCommand {
1979
+ name : "update" ,
1980
+ aliases : & [ ] ,
1981
+ doc : "Write changes only if the file has been modified." ,
1982
+ fun : update,
1983
+ completer : None ,
1984
+ } ,
1960
1985
TypableCommand {
1961
1986
name : "lsp-restart" ,
1962
1987
aliases : & [ ] ,
You can’t perform that action at this time.
0 commit comments