Commit fbc47000c4

fbc47000c499879bee599c847d9bd83ebafcc341

parent: 37c3ecdc3f

Unregistered key

vaw <git@nlih.de> · 2026-11-21 14:30 UTC
committer: <noreply@github.com>

Reply to selected message when entering insert mode in scrollback (#838)

Layout: unified · split

docs/iamb.5 +2
@@ -297,6 +297,8 @@ A message must be sent to the room before marking it read.
297297.El
298298.It Sy read_receipt_display
299299Defines whether or not read confirmations are displayed.
300.It Sy reply_on_insert
301If enabled entering insert mode while a message is selected will reply to that message (unless you are already writing another message).
300302.It Sy request_timeout
301303Defines the maximum time per request in seconds.
302304.It Sy room_labels
src/config/mod.rs +4
@@ -1159,6 +1159,7 @@ pub struct TunableValues {
11591159 /// Display columns reserved for the time gutter, computed from
11601160 /// `time_format` once when the settings are loaded.
11611161 pub time_gutter_width: usize,
1162 pub reply_on_insert: bool,
11621163}
11631164
11641165#[derive(Clone, Debug, Default, Deserialize)]
@@ -1227,6 +1228,7 @@ pub struct Tunables {
12271228 /// An empty string hides the time.
12281229 #[serde(default, deserialize_with = "deserialize_strftime")]
12291230 pub time_format: Option<String>,
1231 pub reply_on_insert: Option<bool>,
12301232}
12311233
12321234impl Tunables {
@@ -1290,6 +1292,7 @@ impl Tunables {
12901292 send_on_enter: self.send_on_enter.or(other.send_on_enter),
12911293 date_format: self.date_format.or(other.date_format),
12921294 time_format: self.time_format.or(other.time_format),
1295 reply_on_insert: self.reply_on_insert.or(other.reply_on_insert),
12931296 }
12941297 }
12951298
@@ -1351,6 +1354,7 @@ impl Tunables {
13511354 date_format: self.date_format.unwrap_or_else(|| DEFAULT_DATE_FORMAT.to_owned()),
13521355 time_format,
13531356 time_gutter_width,
1357 reply_on_insert: self.reply_on_insert.unwrap_or_default(),
13541358 }
13551359 }
13561360}
src/tests.rs +1
@@ -215,6 +215,7 @@ pub fn mock_tunables() -> TunableValues {
215215 date_format: "%A, %B %d %Y".to_string(),
216216 time_format: " [%T]".to_string(),
217217 time_gutter_width: 12,
218 reply_on_insert: false,
218219 }
219220}
220221
src/windows/room/chat.rs +107 −10
@@ -596,8 +596,19 @@ impl ChatState {
596596 &mut self,
597597 act: &EditorAction,
598598 ctx: &ProgramContext,
599 info: &RoomInfo,
600 settings: &ApplicationSettings,
599601 ) -> Option<EditorAction> {
600 auto_toggle_focus(&mut self.focus, act, ctx, &self.scrollback, &mut self.tbox)
602 auto_toggle_focus(
603 &mut self.focus,
604 act,
605 ctx,
606 &self.scrollback,
607 &mut self.tbox,
608 &mut self.reply_to,
609 info,
610 settings,
611 )
601612 }
602613
603614 pub fn typing_notice(
@@ -1119,7 +1130,8 @@ impl Editable<ProgramContext, ProgramStore, IambInfo> for ChatState {
11191130 ) -> EditResult<EditInfo, IambInfo> {
11201131 // Check whether we should automatically switch between the message bar
11211132 // or message scrollback, and use an adjusted action if we do so.
1122 let adjusted = self.auto_toggle_focus(act, ctx);
1133 let info = store.application.rooms.get_or_default(self.room_id.clone());
1134 let adjusted = self.auto_toggle_focus(act, ctx, info, &store.application.settings);
11231135 let act = adjusted.as_ref().unwrap_or(act);
11241136
11251137 // Send typing notice if needed.
@@ -1478,23 +1490,42 @@ fn cmd(open_command: &Vec<String>) -> Option<Command> {
14781490 None
14791491}
14801492
1481pub fn auto_toggle_focus(
1493#[expect(
1494 clippy::too_many_arguments,
1495 reason = "this is only a seperate function to make testing easier"
1496)]
1497fn auto_toggle_focus(
14821498 focus: &mut RoomFocus,
14831499 act: &EditorAction,
14841500 ctx: &ProgramContext,
14851501 scrollback: &ScrollbackState,
14861502 tbox: &mut TextBoxState<IambInfo>,
1503 reply_to: &mut Option<MessageKey>,
1504 info: &RoomInfo,
1505 settings: &ApplicationSettings,
14871506) -> Option<EditorAction> {
14881507 let is_insert = ctx.get_insert_style().is_some();
14891508
14901509 match (focus, act) {
14911510 (f @ RoomFocus::Scrollback, _) if is_insert => {
14921511 // Insert mode commands should switch focus.
1512 if settings.tunables.reply_on_insert &&
1513 reply_to.is_none() &&
1514 !tbox.get_text().is_empty()
1515 {
1516 *reply_to = scrollback.get_key(info);
1517 }
14931518 f.toggle();
14941519 None
14951520 },
14961521 (f @ RoomFocus::Scrollback, EditorAction::InsertText(_)) => {
14971522 // Pasting or otherwise inserting text should switch.
1523 if settings.tunables.reply_on_insert &&
1524 reply_to.is_none() &&
1525 !tbox.get_text().is_empty()
1526 {
1527 *reply_to = scrollback.get_key(info);
1528 }
14981529 f.toggle();
14991530 None
15001531 },
@@ -1670,6 +1701,9 @@ mod tests {
16701701 let id = IambBufferId::Room(room_id, RoomView::Main, RoomFocus::MessageBar);
16711702 let ebuf = store.load_buffer(id);
16721703 let mut tbox = TextBoxState::new(ebuf);
1704 let mut reply_to = None;
1705 let info = RoomInfo::default();
1706 let settings = &store.application.settings;
16731707
16741708 // Start out focused on the scrollback.
16751709 let mut focused = RoomFocus::Scrollback;
@@ -1680,43 +1714,106 @@ mod tests {
16801714 MoveDir1D::Next,
16811715 1.into(),
16821716 ));
1683 let res = auto_toggle_focus(&mut focused, &act, &ctx, &scrollback, &mut tbox);
1717 let res = auto_toggle_focus(
1718 &mut focused,
1719 &act,
1720 &ctx,
1721 &scrollback,
1722 &mut tbox,
1723 &mut reply_to,
1724 &info,
1725 settings,
1726 );
16841727 assert_eq!(focused, RoomFocus::MessageBar);
16851728 assert!(res.is_none());
16861729
16871730 // Going down in message bar doesn't toggle:
16881731 let act = move_line!(MoveDir1D::Next, 1);
1689 let res = auto_toggle_focus(&mut focused, &act, &ctx, &scrollback, &mut tbox);
1732 let res = auto_toggle_focus(
1733 &mut focused,
1734 &act,
1735 &ctx,
1736 &scrollback,
1737 &mut tbox,
1738 &mut reply_to,
1739 &info,
1740 settings,
1741 );
16901742 assert_eq!(focused, RoomFocus::MessageBar);
16911743 assert!(res.is_none());
16921744
16931745 // But going up will:
16941746 let act = move_line!(MoveDir1D::Previous, 1);
1695 let res = auto_toggle_focus(&mut focused, &act, &ctx, &scrollback, &mut tbox);
1747 let res = auto_toggle_focus(
1748 &mut focused,
1749 &act,
1750 &ctx,
1751 &scrollback,
1752 &mut tbox,
1753 &mut reply_to,
1754 &info,
1755 settings,
1756 );
16961757 assert_eq!(focused, RoomFocus::Scrollback);
16971758 assert_eq!(res, Some(move_line!(MoveDir1D::Previous, 0)));
16981759
16991760 // Going up in scrollback doesn't toggle:
17001761 let act = move_line!(MoveDir1D::Previous, 1);
1701 let res = auto_toggle_focus(&mut focused, &act, &ctx, &scrollback, &mut tbox);
1762 let res = auto_toggle_focus(
1763 &mut focused,
1764 &act,
1765 &ctx,
1766 &scrollback,
1767 &mut tbox,
1768 &mut reply_to,
1769 &info,
1770 settings,
1771 );
17021772 assert_eq!(focused, RoomFocus::Scrollback);
17031773 assert_eq!(res, None);
17041774
17051775 // And then go back down:
17061776 let act = move_line!(MoveDir1D::Next, 1);
1707 let res = auto_toggle_focus(&mut focused, &act, &ctx, &scrollback, &mut tbox);
1777 let res = auto_toggle_focus(
1778 &mut focused,
1779 &act,
1780 &ctx,
1781 &scrollback,
1782 &mut tbox,
1783 &mut reply_to,
1784 &info,
1785 settings,
1786 );
17081787 assert_eq!(focused, RoomFocus::MessageBar);
17091788 assert_eq!(res, Some(move_line!(MoveDir1D::Next, 0)));
17101789
17111790 // Go up 2 will go up 1 in scrollback:
17121791 let act = move_line!(MoveDir1D::Previous, 2);
1713 let res = auto_toggle_focus(&mut focused, &act, &ctx, &scrollback, &mut tbox);
1792 let res = auto_toggle_focus(
1793 &mut focused,
1794 &act,
1795 &ctx,
1796 &scrollback,
1797 &mut tbox,
1798 &mut reply_to,
1799 &info,
1800 settings,
1801 );
17141802 assert_eq!(focused, RoomFocus::Scrollback);
17151803 assert_eq!(res, Some(move_line!(MoveDir1D::Previous, 1)));
17161804
17171805 // Go down 3 will go down 2 in messagebar:
17181806 let act = move_line!(MoveDir1D::Next, 3);
1719 let res = auto_toggle_focus(&mut focused, &act, &ctx, &scrollback, &mut tbox);
1807 let res = auto_toggle_focus(
1808 &mut focused,
1809 &act,
1810 &ctx,
1811 &scrollback,
1812 &mut tbox,
1813 &mut reply_to,
1814 &info,
1815 settings,
1816 );
17201817 assert_eq!(focused, RoomFocus::MessageBar);
17211818 assert_eq!(res, Some(move_line!(MoveDir1D::Next, 2)));
17221819 }
src/windows/room/scrollback.rs +1 −1
@@ -141,7 +141,7 @@ impl ScrollbackState {
141141 self.viewctx.dimensions = (area.width as usize, area.height as usize);
142142 }
143143
144 pub fn get_key(&self, info: &mut RoomInfo) -> Option<MessageKey> {
144 pub fn get_key(&self, info: &RoomInfo) -> Option<MessageKey> {
145145 self.cursor
146146 .timestamp
147147 .clone()