fix sqlez warning, introduce tab and enter bindings to vim for inputing tab and enter text when waiting for text

This commit is contained in:
Kay Simmons 2023-02-10 15:41:19 -08:00
parent 3d53336916
commit 459060764a
3 changed files with 21 additions and 18 deletions

View File

@ -315,7 +315,8 @@
{ {
"context": "Editor && VimWaiting", "context": "Editor && VimWaiting",
"bindings": { "bindings": {
// "*": "gpui::KeyPressed", "tab": "vim::Tab",
"enter": "vim::Enter",
"escape": "editor::Cancel" "escape": "editor::Cancel"
} }
} }

View File

@ -83,7 +83,6 @@ impl Connection {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use indoc::indoc; use indoc::indoc;
use sqlez_macros::sql;
use crate::connection::Connection; use crate::connection::Connection;
@ -288,21 +287,18 @@ mod test {
let connection = Connection::open_memory(Some("test_create_alter_drop")); let connection = Connection::open_memory(Some("test_create_alter_drop"));
connection connection
.migrate( .migrate("first_migration", &["CREATE TABLE table1(a TEXT) STRICT;"])
"first_migration",
&[sql!( CREATE TABLE table1(a TEXT) STRICT; )],
)
.unwrap(); .unwrap();
connection connection
.exec(sql!( INSERT INTO table1(a) VALUES ("test text"); )) .exec("INSERT INTO table1(a) VALUES (\"test text\");")
.unwrap()() .unwrap()()
.unwrap(); .unwrap();
connection connection
.migrate( .migrate(
"second_migration", "second_migration",
&[sql!( &[indoc! {"
CREATE TABLE table2(b TEXT) STRICT; CREATE TABLE table2(b TEXT) STRICT;
INSERT INTO table2 (b) INSERT INTO table2 (b)
@ -311,16 +307,11 @@ mod test {
DROP TABLE table1; DROP TABLE table1;
ALTER TABLE table2 RENAME TO table1; ALTER TABLE table2 RENAME TO table1;
)], "}],
) )
.unwrap(); .unwrap();
let res = &connection let res = &connection.select::<String>("SELECT b FROM table1").unwrap()().unwrap()[0];
.select::<String>(sql!(
SELECT b FROM table1
))
.unwrap()()
.unwrap()[0];
assert_eq!(res, "test text"); assert_eq!(res, "test text");
} }

View File

@ -15,7 +15,7 @@ use std::sync::Arc;
use command_palette::CommandPaletteFilter; use command_palette::CommandPaletteFilter;
use editor::{Bias, Cancel, Editor, EditorMode}; use editor::{Bias, Cancel, Editor, EditorMode};
use gpui::{ use gpui::{
impl_actions, MutableAppContext, Subscription, ViewContext, ViewHandle, WeakViewHandle, actions, impl_actions, MutableAppContext, Subscription, ViewContext, ViewHandle, WeakViewHandle,
}; };
use language::CursorShape; use language::CursorShape;
use motion::Motion; use motion::Motion;
@ -35,6 +35,7 @@ pub struct PushOperator(pub Operator);
#[derive(Clone, Deserialize, PartialEq)] #[derive(Clone, Deserialize, PartialEq)]
struct Number(u8); struct Number(u8);
actions!(vim, [Tab, Enter]);
impl_actions!(vim, [Number, SwitchMode, PushOperator]); impl_actions!(vim, [Number, SwitchMode, PushOperator]);
pub fn init(cx: &mut MutableAppContext) { pub fn init(cx: &mut MutableAppContext) {
@ -74,8 +75,16 @@ pub fn init(cx: &mut MutableAppContext) {
} }
}); });
cx.add_action(|_: &mut Workspace, _: &Tab, cx| {
Vim::active_editor_input_ignored(" ".into(), cx)
});
cx.add_action(|_: &mut Workspace, _: &Enter, cx| {
Vim::active_editor_input_ignored("\n".into(), cx)
});
// Sync initial settings with the rest of the app // Sync initial settings with the rest of the app
Vim::update(cx, |state, cx| state.sync_vim_settings(cx)); Vim::update(cx, |vim, cx| vim.sync_vim_settings(cx));
// Any time settings change, update vim mode to match // Any time settings change, update vim mode to match
cx.observe_global::<Settings, _>(|cx| { cx.observe_global::<Settings, _>(|cx| {
@ -99,7 +108,9 @@ pub fn observe_keystrokes(window_id: usize, cx: &mut MutableAppContext) {
} }
Vim::update(cx, |vim, cx| match vim.active_operator() { Vim::update(cx, |vim, cx| match vim.active_operator() {
Some(Operator::FindForward { .. } | Operator::FindBackward { .. }) => {} Some(
Operator::FindForward { .. } | Operator::FindBackward { .. } | Operator::Replace,
) => {}
Some(_) => { Some(_) => {
vim.clear_operator(cx); vim.clear_operator(cx);
} }