Skip to content
This repository was archived by the owner on Dec 28, 2021. It is now read-only.

Commit e3f909b

Browse files
committed
add Alt+E shotcut to exit from editor #2
1 parent b087871 commit e3f909b

File tree

7 files changed

+11
-20
lines changed

7 files changed

+11
-20
lines changed

assets/logo.png

-37.2 KB
Binary file not shown.

assets/logo.svg

Lines changed: 0 additions & 16 deletions
This file was deleted.

config/ox.ron

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
keys: {
131131
// Keybinding: [Oxa commands]
132132
Ctrl(Char('q')): ["quit"], // Quit current document
133+
Alt(Char('e')): ["exit"], // Exit from current document
133134
Ctrl(Char('s')): ["save"], // Save current document
134135
Alt(Char('s')): ["save ?"], // Save current document as
135136
Ctrl(Char('w')): ["save *"], // Save all open documents

src/config.rs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/editor.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ pub struct Editor {
112112
pub status: Status, // Holding the status of the config
113113
config_path: String, // Holds the file path of the config file
114114
quit: bool, // Toggle for cleanly quitting the editor
115+
exit: bool, // Toggle for cleanly quitting the editor
115116
term: Terminal, // For the handling of the terminal
116117
doc: Vec<Document>, // For holding our document
117118
tab: usize, // Holds the number of the current tab
@@ -212,6 +213,7 @@ impl Editor {
212213
// Create the new editor instance
213214
Ok(Self {
214215
quit: false,
216+
exit: false,
215217
// Display information about the config file into text for the status line
216218
term,
217219
tab: 0,
@@ -507,7 +509,7 @@ impl Editor {
507509
fn quit_document(&mut self, force: bool) {
508510
// For handling a quit event
509511
if let KeyBinding::Ctrl(_) | KeyBinding::Alt(_) = self.keypress {
510-
if force || self.dirty_prompt(self.keypress, "quit") {
512+
if force || self.dirty_prompt(self.keypress, "quit") || self.dirty_prompt(self.keypress, "exit") {
511513
if self.doc.len() <= 1 {
512514
// Quit Ox
513515
self.quit = true;
@@ -527,7 +529,7 @@ impl Editor {
527529
fn quit_all(&mut self, force: bool) {
528530
// Quit all the documents in the editor
529531
self.tab = 0;
530-
while !self.quit {
532+
while !self.quit || !self.exit {
531533
self.execute(Event::Quit(force), false);
532534
}
533535
}
@@ -561,6 +563,7 @@ impl Editor {
561563
Event::Save(file, prompt) => self.save_document(file, prompt),
562564
Event::SaveAll => self.save_every_document(),
563565
Event::Quit(force) => self.quit_document(force),
566+
Event::Exit(force) => self.quit_document(force),
564567
Event::QuitAll(force) => self.quit_all(force),
565568
Event::NextTab => self.next_tab(),
566569
Event::PrevTab => self.prev_tab(),

src/oxa.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub fn interpret_line(
4040
"commit" => events.push(Event::Commit),
4141
"redo" => events.push(Event::Redo),
4242
"quit" => events.push(quit_command(&args)),
43+
"exit" => events.push(quit_command(&args)),
4344
"prev" => events.push(Event::PrevTab),
4445
"next" => events.push(Event::NextTab),
4546
"set" => events.push(set_command(&args, &cursor, &rows)),
@@ -139,7 +140,8 @@ fn quit_command(args: &[&str]) -> Event {
139140
if args.contains(&"*") {
140141
Event::QuitAll(args.contains(&"!"))
141142
} else {
142-
Event::Quit(args.contains(&"!"))
143+
Event::Quit(args.contains(&"!"));
144+
Event::Exit(args.contains(&"!"))
143145
}
144146
}
145147

src/undo.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub enum Event {
4646
Redo, // Redo event
4747
Commit, // Commit undo event
4848
Quit(bool), // Quit document
49+
Exit(bool), // Exit document
4950
QuitAll(bool), // Quit all
5051
NextTab, // Next tab
5152
PrevTab, // Previous tab

0 commit comments

Comments
 (0)