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.
297.El 297.El
298.It Sy read_receipt_display 298.It Sy read_receipt_display
299Defines whether or not read confirmations are displayed. 299Defines 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).
300.It Sy request_timeout 302.It Sy request_timeout
301Defines the maximum time per request in seconds. 303Defines the maximum time per request in seconds.
302.It Sy room_labels 304.It Sy room_labels
src/config/mod.rs +4
@@ -1159,6 +1159,7 @@ pub struct TunableValues {
1159 /// Display columns reserved for the time gutter, computed from 1159 /// Display columns reserved for the time gutter, computed from
1160 /// `time_format` once when the settings are loaded. 1160 /// `time_format` once when the settings are loaded.
1161 pub time_gutter_width: usize, 1161 pub time_gutter_width: usize,
1162 pub reply_on_insert: bool,
1162} 1163}
1163 1164
1164#[derive(Clone, Debug, Default, Deserialize)] 1165#[derive(Clone, Debug, Default, Deserialize)]
@@ -1227,6 +1228,7 @@ pub struct Tunables {
1227 /// An empty string hides the time. 1228 /// An empty string hides the time.
1228 #[serde(default, deserialize_with = "deserialize_strftime")] 1229 #[serde(default, deserialize_with = "deserialize_strftime")]
1229 pub time_format: Option<String>, 1230 pub time_format: Option<String>,
1231 pub reply_on_insert: Option<bool>,
1230} 1232}
1231 1233
1232impl Tunables { 1234impl Tunables {
@@ -1290,6 +1292,7 @@ impl Tunables {
1290 send_on_enter: self.send_on_enter.or(other.send_on_enter), 1292 send_on_enter: self.send_on_enter.or(other.send_on_enter),
1291 date_format: self.date_format.or(other.date_format), 1293 date_format: self.date_format.or(other.date_format),
1292 time_format: self.time_format.or(other.time_format), 1294 time_format: self.time_format.or(other.time_format),
1295 reply_on_insert: self.reply_on_insert.or(other.reply_on_insert),
1293 } 1296 }
1294 } 1297 }
1295 1298
@@ -1351,6 +1354,7 @@ impl Tunables {
1351 date_format: self.date_format.unwrap_or_else(|| DEFAULT_DATE_FORMAT.to_owned()), 1354 date_format: self.date_format.unwrap_or_else(|| DEFAULT_DATE_FORMAT.to_owned()),
1352 time_format, 1355 time_format,
1353 time_gutter_width, 1356 time_gutter_width,
1357 reply_on_insert: self.reply_on_insert.unwrap_or_default(),
1354 } 1358 }
1355 } 1359 }
1356} 1360}
src/tests.rs +1
@@ -215,6 +215,7 @@ pub fn mock_tunables() -> TunableValues {
215 date_format: "%A, %B %d %Y".to_string(), 215 date_format: "%A, %B %d %Y".to_string(),
216 time_format: " [%T]".to_string(), 216 time_format: " [%T]".to_string(),
217 time_gutter_width: 12, 217 time_gutter_width: 12,
218 reply_on_insert: false,
218 } 219 }
219} 220}
220 221
src/windows/room/chat.rs +107 −10
@@ -596,8 +596,19 @@ impl ChatState {
596 &mut self, 596 &mut self,
597 act: &EditorAction, 597 act: &EditorAction,
598 ctx: &ProgramContext, 598 ctx: &ProgramContext,
599 info: &RoomInfo,
600 settings: &ApplicationSettings,
599 ) -> Option<EditorAction> { 601 ) -> 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 )
601 } 612 }
602 613
603 pub fn typing_notice( 614 pub fn typing_notice(
@@ -1119,7 +1130,8 @@ impl Editable<ProgramContext, ProgramStore, IambInfo> for ChatState {
1119 ) -> EditResult<EditInfo, IambInfo> { 1130 ) -> EditResult<EditInfo, IambInfo> {
1120 // Check whether we should automatically switch between the message bar 1131 // Check whether we should automatically switch between the message bar
1121 // or message scrollback, and use an adjusted action if we do so. 1132 // 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);
1123 let act = adjusted.as_ref().unwrap_or(act); 1135 let act = adjusted.as_ref().unwrap_or(act);
1124 1136
1125 // Send typing notice if needed. 1137 // Send typing notice if needed.
@@ -1478,23 +1490,42 @@ fn cmd(open_command: &Vec<String>) -> Option<Command> {
1478 None 1490 None
1479} 1491}
1480 1492
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(
1482 focus: &mut RoomFocus, 1498 focus: &mut RoomFocus,
1483 act: &EditorAction, 1499 act: &EditorAction,
1484 ctx: &ProgramContext, 1500 ctx: &ProgramContext,
1485 scrollback: &ScrollbackState, 1501 scrollback: &ScrollbackState,
1486 tbox: &mut TextBoxState<IambInfo>, 1502 tbox: &mut TextBoxState<IambInfo>,
1503 reply_to: &mut Option<MessageKey>,
1504 info: &RoomInfo,
1505 settings: &ApplicationSettings,
1487) -> Option<EditorAction> { 1506) -> Option<EditorAction> {
1488 let is_insert = ctx.get_insert_style().is_some(); 1507 let is_insert = ctx.get_insert_style().is_some();
1489 1508
1490 match (focus, act) { 1509 match (focus, act) {
1491 (f @ RoomFocus::Scrollback, _) if is_insert => { 1510 (f @ RoomFocus::Scrollback, _) if is_insert => {
1492 // Insert mode commands should switch focus. 1511 // 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 }
1493 f.toggle(); 1518 f.toggle();
1494 None 1519 None
1495 }, 1520 },
1496 (f @ RoomFocus::Scrollback, EditorAction::InsertText(_)) => { 1521 (f @ RoomFocus::Scrollback, EditorAction::InsertText(_)) => {
1497 // Pasting or otherwise inserting text should switch. 1522 // 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 }
1498 f.toggle(); 1529 f.toggle();
1499 None 1530 None
1500 }, 1531 },
@@ -1670,6 +1701,9 @@ mod tests {
1670 let id = IambBufferId::Room(room_id, RoomView::Main, RoomFocus::MessageBar); 1701 let id = IambBufferId::Room(room_id, RoomView::Main, RoomFocus::MessageBar);
1671 let ebuf = store.load_buffer(id); 1702 let ebuf = store.load_buffer(id);
1672 let mut tbox = TextBoxState::new(ebuf); 1703 let mut tbox = TextBoxState::new(ebuf);
1704 let mut reply_to = None;
1705 let info = RoomInfo::default();
1706 let settings = &store.application.settings;
1673 1707
1674 // Start out focused on the scrollback. 1708 // Start out focused on the scrollback.
1675 let mut focused = RoomFocus::Scrollback; 1709 let mut focused = RoomFocus::Scrollback;
@@ -1680,43 +1714,106 @@ mod tests {
1680 MoveDir1D::Next, 1714 MoveDir1D::Next,
1681 1.into(), 1715 1.into(),
1682 )); 1716 ));
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 );
1684 assert_eq!(focused, RoomFocus::MessageBar); 1727 assert_eq!(focused, RoomFocus::MessageBar);
1685 assert!(res.is_none()); 1728 assert!(res.is_none());
1686 1729
1687 // Going down in message bar doesn't toggle: 1730 // Going down in message bar doesn't toggle:
1688 let act = move_line!(MoveDir1D::Next, 1); 1731 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 );
1690 assert_eq!(focused, RoomFocus::MessageBar); 1742 assert_eq!(focused, RoomFocus::MessageBar);
1691 assert!(res.is_none()); 1743 assert!(res.is_none());
1692 1744
1693 // But going up will: 1745 // But going up will:
1694 let act = move_line!(MoveDir1D::Previous, 1); 1746 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 );
1696 assert_eq!(focused, RoomFocus::Scrollback); 1757 assert_eq!(focused, RoomFocus::Scrollback);
1697 assert_eq!(res, Some(move_line!(MoveDir1D::Previous, 0))); 1758 assert_eq!(res, Some(move_line!(MoveDir1D::Previous, 0)));
1698 1759
1699 // Going up in scrollback doesn't toggle: 1760 // Going up in scrollback doesn't toggle:
1700 let act = move_line!(MoveDir1D::Previous, 1); 1761 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 );
1702 assert_eq!(focused, RoomFocus::Scrollback); 1772 assert_eq!(focused, RoomFocus::Scrollback);
1703 assert_eq!(res, None); 1773 assert_eq!(res, None);
1704 1774
1705 // And then go back down: 1775 // And then go back down:
1706 let act = move_line!(MoveDir1D::Next, 1); 1776 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 );
1708 assert_eq!(focused, RoomFocus::MessageBar); 1787 assert_eq!(focused, RoomFocus::MessageBar);
1709 assert_eq!(res, Some(move_line!(MoveDir1D::Next, 0))); 1788 assert_eq!(res, Some(move_line!(MoveDir1D::Next, 0)));
1710 1789
1711 // Go up 2 will go up 1 in scrollback: 1790 // Go up 2 will go up 1 in scrollback:
1712 let act = move_line!(MoveDir1D::Previous, 2); 1791 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 );
1714 assert_eq!(focused, RoomFocus::Scrollback); 1802 assert_eq!(focused, RoomFocus::Scrollback);
1715 assert_eq!(res, Some(move_line!(MoveDir1D::Previous, 1))); 1803 assert_eq!(res, Some(move_line!(MoveDir1D::Previous, 1)));
1716 1804
1717 // Go down 3 will go down 2 in messagebar: 1805 // Go down 3 will go down 2 in messagebar:
1718 let act = move_line!(MoveDir1D::Next, 3); 1806 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 );
1720 assert_eq!(focused, RoomFocus::MessageBar); 1817 assert_eq!(focused, RoomFocus::MessageBar);
1721 assert_eq!(res, Some(move_line!(MoveDir1D::Next, 2))); 1818 assert_eq!(res, Some(move_line!(MoveDir1D::Next, 2)));
1722 } 1819 }
src/windows/room/scrollback.rs +1 −1
@@ -141,7 +141,7 @@ impl ScrollbackState {
141 self.viewctx.dimensions = (area.width as usize, area.height as usize); 141 self.viewctx.dimensions = (area.width as usize, area.height as usize);
142 } 142 }
143 143
144 pub fn get_key(&self, info: &mut RoomInfo) -> Option<MessageKey> { 144 pub fn get_key(&self, info: &RoomInfo) -> Option<MessageKey> {
145 self.cursor 145 self.cursor
146 .timestamp 146 .timestamp
147 .clone() 147 .clone()