mirror of https://github.com/bobwen-dev/hunter
switch tabs with f keys
This commit is contained in:
parent
e63c65ab7d
commit
9cc1ce1a44
|
@ -89,6 +89,10 @@ impl Tabbable for TabView<FileBrowser> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn goto_tab(&mut self, index: usize) -> HResult<()> {
|
||||||
|
self.goto_tab_(index)
|
||||||
|
}
|
||||||
|
|
||||||
fn get_tab_names(&self) -> Vec<Option<String>> {
|
fn get_tab_names(&self) -> Vec<Option<String>> {
|
||||||
self.widgets.iter().map(|filebrowser| {
|
self.widgets.iter().map(|filebrowser| {
|
||||||
let path = filebrowser.cwd.path();
|
let path = filebrowser.cwd.path();
|
||||||
|
@ -106,7 +110,7 @@ impl Tabbable for TabView<FileBrowser> {
|
||||||
self.active_tab_mut_()
|
self.active_tab_mut_()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_next_tab(&mut self) -> HResult<()> {
|
fn on_tab_switch(&mut self) -> HResult<()> {
|
||||||
self.active_tab_mut().refresh()
|
self.active_tab_mut().refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ impl MiniBuffer {
|
||||||
self.completions.clear();
|
self.completions.clear();
|
||||||
self.last_completion = None;
|
self.last_completion = None;
|
||||||
|
|
||||||
self.get_core()?.screen.lock()?.cursor_hide();
|
self.get_core()?.screen.lock()?.cursor_hide().log();
|
||||||
|
|
||||||
self.popup()?;
|
self.popup()?;
|
||||||
|
|
||||||
|
@ -316,6 +316,11 @@ impl Widget for MiniBuffer {
|
||||||
Key::Char('\t') => {
|
Key::Char('\t') => {
|
||||||
self.complete()?;
|
self.complete()?;
|
||||||
}
|
}
|
||||||
|
Key::F(n) => {
|
||||||
|
let fnstr = format!("${}", n-1);
|
||||||
|
self.input.insert_str(self.position, &fnstr);
|
||||||
|
self.position += 2;
|
||||||
|
}
|
||||||
Key::Backspace => {
|
Key::Backspace => {
|
||||||
if self.position != 0 {
|
if self.position != 0 {
|
||||||
self.input.remove(self.position - 1);
|
self.input.remove(self.position - 1);
|
||||||
|
|
|
@ -7,7 +7,8 @@ pub trait Tabbable {
|
||||||
fn new_tab(&mut self) -> HResult<()>;
|
fn new_tab(&mut self) -> HResult<()>;
|
||||||
fn close_tab(&mut self) -> HResult<()>;
|
fn close_tab(&mut self) -> HResult<()>;
|
||||||
fn next_tab(&mut self) -> HResult<()>;
|
fn next_tab(&mut self) -> HResult<()>;
|
||||||
fn on_next_tab(&mut self) -> HResult<()> {
|
fn goto_tab(&mut self, index: usize) -> HResult<()>;
|
||||||
|
fn on_tab_switch(&mut self) -> HResult<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn get_tab_names(&self) -> Vec<Option<String>>;
|
fn get_tab_names(&self) -> Vec<Option<String>>;
|
||||||
|
@ -16,6 +17,7 @@ pub trait Tabbable {
|
||||||
fn on_key_sub(&mut self, key: Key) -> HResult<()>;
|
fn on_key_sub(&mut self, key: Key) -> HResult<()>;
|
||||||
fn on_key(&mut self, key: Key) -> HResult<()> {
|
fn on_key(&mut self, key: Key) -> HResult<()> {
|
||||||
match key {
|
match key {
|
||||||
|
Key::F(n) => self.goto_tab(n as usize -1),
|
||||||
Key::Ctrl('t') => self.new_tab(),
|
Key::Ctrl('t') => self.new_tab(),
|
||||||
Key::Ctrl('w') => self.close_tab(),
|
Key::Ctrl('w') => self.close_tab(),
|
||||||
Key::Char('\t') => self.next_tab(),
|
Key::Char('\t') => self.next_tab(),
|
||||||
|
@ -65,6 +67,14 @@ impl<T> TabView<T> where T: Widget, TabView<T>: Tabbable {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn goto_tab_(&mut self, index: usize) -> HResult<()> {
|
||||||
|
if index < self.widgets.len() {
|
||||||
|
self.active = index;
|
||||||
|
self.on_tab_switch().log();
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn active_tab_(&self) -> &T {
|
pub fn active_tab_(&self) -> &T {
|
||||||
&self.widgets[self.active]
|
&self.widgets[self.active]
|
||||||
}
|
}
|
||||||
|
@ -84,7 +94,7 @@ impl<T> TabView<T> where T: Widget, TabView<T>: Tabbable {
|
||||||
} else {
|
} else {
|
||||||
self.active += 1
|
self.active += 1
|
||||||
}
|
}
|
||||||
self.on_next_tab().log();
|
self.on_tab_switch().log();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue