summaryrefslogtreecommitdiff
path: root/command.go
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2026-01-22 18:51:24 +0100
committerMitja Felicijan <mitja.felicijan@gmail.com>2026-01-22 18:51:24 +0100
commit3d25687572aa9373e324a06413ceffba15d6bceb (patch)
treea0d59a08deefbef91d69f04da1e9e579f33e8723 /command.go
parentb3d11e9787ac11c41949dea044b57afdbcc5836a (diff)
downloadqwe-editor-3d25687572aa9373e324a06413ceffba15d6bceb.tar.gz
Add :w filename and :n new buffer
Diffstat (limited to 'command.go')
-rw-r--r--command.go23
1 files changed, 20 insertions, 3 deletions
diff --git a/command.go b/command.go
index e6fc9eb..e8f4536 100644
--- a/command.go
+++ b/command.go
@@ -34,7 +34,7 @@ func (ch *Command) IsValidCommand(cmd string) bool {
// Valid if it's a known command
switch cmd {
- case "q", "Q", "q!", "Q!", "w", "W", "wa", "WA", "wq", "WQ", "waq", "WAQ", "reload", "bd", "bd!", "debug", "help", "mouse", "e", "edit":
+ case "q", "Q", "q!", "Q!", "w", "W", "wa", "WA", "wq", "WQ", "waq", "WAQ", "reload", "bd", "bd!", "debug", "help", "mouse", "e", "edit", "n":
return true
}
@@ -43,6 +43,11 @@ func (ch *Command) IsValidCommand(cmd string) bool {
return true
}
+ // Valid if it starts with w (write with filename)
+ if strings.HasPrefix(cmd, "w ") {
+ return true
+ }
+
// Everything else is considered invalid (will show "Command not found" message)
return false
}
@@ -104,7 +109,10 @@ func (ch *Command) Handle(cmd string) {
case cmd == "q!" || cmd == "Q!":
ch.quit(true)
case cmd == "w" || cmd == "W":
- ch.write()
+ ch.write("")
+ case strings.HasPrefix(cmd, "w "):
+ filename := strings.TrimSpace(strings.TrimPrefix(cmd, "w "))
+ ch.write(filename)
case cmd == "wa" || cmd == "WA":
ch.writeAll()
case cmd == "wq" || cmd == "WQ":
@@ -129,6 +137,8 @@ func (ch *Command) Handle(cmd string) {
ch.bufferDelete(false)
case cmd == "bd!":
ch.bufferDelete(true)
+ case cmd == "n":
+ ch.e.NewBuffer()
case cmd == "debug":
ch.e.toggleDebugWindow()
case cmd == "help":
@@ -217,7 +227,14 @@ func (ch *Command) quit(force bool) {
}
// write saves the current active buffer to disk.
-func (ch *Command) write() {
+func (ch *Command) write(filename string) {
+ if filename != "" {
+ b := ch.e.activeBuffer()
+ if b != nil {
+ b.filename = filename
+ b.fileType = getFileType(filename)
+ }
+ }
err := ch.e.SaveFile(false)
if err != nil {
// Handle conflict if the file was changed externally.