Skip to content

Commit be3d27d

Browse files
authored
Add option to insert a linebreak on <enter> instead of sending a message (#727)
1 parent d9e4458 commit be3d27d

5 files changed

Lines changed: 13 additions & 4 deletions

File tree

‎docs/iamb.5‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ A message must be sent to the room before marking it read.
272272
Defines whether or not read confirmations are displayed.
273273
.It Sy request_timeout
274274
Defines the maximum time per request in seconds.
275+
.It Sy send_on_enter
276+
If
277+
.Sy true
278+
(the default), pressing enter in insert mode will send the message instead of inserting a linebreak.
275279
.It Sy sort
276280
Configures how to sort the lists shown in windows like
277281
.Sy :rooms

‎src/config.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ pub struct TunableValues {
872872
pub default_split: SplitDirection,
873873
pub ssl_verify: bool,
874874
pub cache_policy: MediaRetentionPolicy,
875+
pub send_on_enter: bool,
875876
}
876877

877878
#[derive(Clone, Debug, Default, Deserialize)]
@@ -928,6 +929,7 @@ pub struct Tunables {
928929
pub default_split: Option<SplitDirection>,
929930
pub ssl_verify: Option<bool>,
930931
pub cache_policy: Option<MediaRetentionPolicy>,
932+
pub send_on_enter: Option<bool>,
931933
}
932934

933935
impl Tunables {
@@ -982,6 +984,7 @@ impl Tunables {
982984
default_split: self.default_split.or(other.default_split),
983985
ssl_verify: self.ssl_verify.or(other.ssl_verify),
984986
cache_policy: self.cache_policy.or(other.cache_policy),
987+
send_on_enter: self.send_on_enter.or(other.send_on_enter),
985988
}
986989
}
987990

@@ -1028,6 +1031,7 @@ impl Tunables {
10281031
default_split: self.default_split.unwrap_or_default(),
10291032
ssl_verify: self.ssl_verify.unwrap_or(true),
10301033
cache_policy: self.cache_policy.unwrap_or_default(),
1034+
send_on_enter: self.send_on_enter.unwrap_or(true),
10311035
}
10321036
}
10331037
}

‎src/keybindings.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use modalkit::env::vim::keybindings::{InputStep, VimBindings};
99
use modalkit::keybindings::{EdgeEvent, EdgeRepeat, InputBindings};
1010

1111
use crate::base::{Keybindings, MATRIX_ID_WORD};
12-
use crate::config::{Keys, SplitDirection};
12+
use crate::config::{Keys, SplitDirection, TunableValues};
1313
use crate::prelude::*;
1414

1515
pub type IambStep = InputStep<IambInfo>;
@@ -19,11 +19,11 @@ fn once(key: &TerminalKey) -> (EdgeRepeat, EdgeEvent<TerminalKey, CommonKeyClass
1919
}
2020

2121
/// Initialize the default keybinding state.
22-
pub fn setup_keybindings() -> Keybindings {
22+
pub fn setup_keybindings(tunables: &TunableValues) -> Keybindings {
2323
let mut ism = Keybindings::empty();
2424

2525
let vim = VimBindings::default()
26-
.submit_on_enter(false)
26+
.submit_on_enter(!tunables.send_on_enter)
2727
.cursor_open(MATRIX_ID_WORD.clone());
2828

2929
vim.setup(&mut ism);

‎src/main.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl Application {
288288
let backend = CrosstermBackend::new(stdout());
289289
let terminal = Terminal::new(backend)?;
290290

291-
let mut bindings = crate::keybindings::setup_keybindings();
291+
let mut bindings = crate::keybindings::setup_keybindings(&settings.tunables);
292292
settings.setup(&mut bindings);
293293
let bindings = KeyManager::new(bindings);
294294

‎src/tests.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ pub fn mock_tunables() -> TunableValues {
201201
default_split: Default::default(),
202202
ssl_verify: true,
203203
cache_policy: Default::default(),
204+
send_on_enter: true,
204205
}
205206
}
206207

0 commit comments

Comments
 (0)