Skip to content

Added q! - command#25

Merged
itchyny merged 2 commits intoitchyny:masterfrom
Zarathustra2:master
Aug 30, 2019
Merged

Added q! - command#25
itchyny merged 2 commits intoitchyny:masterfrom
Zarathustra2:master

Conversation

@Zarathustra2
Copy link
Contributor

Hey,

I have added the q! command, which discards all changes and quits the editor.
Furthermore, if someone now tries to quit with the q command while changes have not been saved, it will fail and display an error message.

Since this is my first time contributing to a go open source project, I would appreciate any feedback!

Best regards,
Dario! :)

@itchyny
Copy link
Owner

itchyny commented Aug 28, 2019

This sounds nice. I'll take a look later.


{"exi[t]", event.Quit},
{"q[uit]", event.Quit},
{"q!", event.ForceQuit},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to support q[uit]! but I remember I didn't implement the parser to accept this so I'll fix this after merging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I tried q[uit]! as well, but failed due to the parsing. Do you want me to add a failing test case for q[uit]! ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, thanks. I'll take care of it.

@itchyny
Copy link
Owner

itchyny commented Aug 28, 2019

Your pull request updates unsavedChanges for only some limited operations. You can find all the changes by searching /b.buffer./, for example, window#insert, window#replace, window#cut or window#paste. Maybe changedTick is incremented as well. Also, please rename unsavedChanges to modified, which reminds me &modified of Vim.

changes sample:

@@ -356,11 +356,13 @@ func (w *window) state(width, height int) (*state.WindowState, error) {
 func (w *window) insert(offset int64, c byte) {
 	w.buffer.Insert(offset, c)
 	w.changedTick++
+	w.modified = true
 }
 
 func (w *window) replace(offset int64, c byte) {
 	w.buffer.Replace(offset, c)
 	w.changedTick++
+	w.modified = true
 }
 
 func (w *window) undoReplace(offset int64) {

@Zarathustra2
Copy link
Contributor Author

Hey @itchyny,

Thanks for reviewing my PR! :)

I have updated the files as requested, would you mind taking another look?

Best regards!

@itchyny
Copy link
Owner

itchyny commented Aug 30, 2019

Great, thank you.

@itchyny itchyny merged commit cfffd40 into itchyny:master Aug 30, 2019
@itchyny
Copy link
Owner

itchyny commented Sep 8, 2019

Now that I improved the cmdline parser, you can use both :q!, :quit!.

@Zarathustra2
Copy link
Contributor Author

Nice thanks! :) @itchyny

@Zarathustra2 Zarathustra2 mentioned this pull request Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants