Commit 6d0cdbdfe1

6d0cdbdfe179da3424e225e76b80f4b06b54029e

parent: 50424f440b

Unregistered key

Ulyssa <git@ulyssa.dev> · 2026-09-11 23:02 UTC
committer: <noreply@github.com>

Allow user's to specify a default register for editing (#683)

Layout: unified · split

Cargo.lock +12 −12
@@ -1651,9 +1651,9 @@ dependencies = [
1651 1651
1652[[package]] 1652[[package]]
1653name = "editor-types" 1653name = "editor-types"
1654version = "0.0.3" 1654version = "0.0.4"
1655source = "registry+https://github.com/rust-lang/crates.io-index" 1655source = "registry+https://github.com/rust-lang/crates.io-index"
1656checksum = "47b92e9f52720323ec57f764607c7ee72cc6e15a346ad7ad82bfcec3c6dfd610" 1656checksum = "4f43aac4281b3b2127f017a09550a0133d11f5b51e0678d87a1a086767096182"
1657dependencies = [ 1657dependencies = [
1658 "bitflags 2.13.0", 1658 "bitflags 2.13.0",
1659 "editor-types-macros", 1659 "editor-types-macros",
@@ -1663,9 +1663,9 @@ dependencies = [
1663 1663
1664[[package]] 1664[[package]]
1665name = "editor-types-macros" 1665name = "editor-types-macros"
1666version = "0.0.3" 1666version = "0.0.4"
1667source = "registry+https://github.com/rust-lang/crates.io-index" 1667source = "registry+https://github.com/rust-lang/crates.io-index"
1668checksum = "096cf10a3cc9646686e5b715222b919f55b133e9264359a491048946b5ecde74" 1668checksum = "786e57be6adb4b06cfbdfa2680b864382ba1d040e7e20e065b0850239565a477"
1669dependencies = [ 1669dependencies = [
1670 "editor-types-parser", 1670 "editor-types-parser",
1671 "nom 8.0.0", 1671 "nom 8.0.0",
@@ -1676,9 +1676,9 @@ dependencies = [
1676 1676
1677[[package]] 1677[[package]]
1678name = "editor-types-parser" 1678name = "editor-types-parser"
1679version = "0.0.3" 1679version = "0.0.4"
1680source = "registry+https://github.com/rust-lang/crates.io-index" 1680source = "registry+https://github.com/rust-lang/crates.io-index"
1681checksum = "d6d295ca162dafc88ce70da46d7378ee0f932b7a793f82a50df28933cf1d1854" 1681checksum = "9821f63ec0570a7b063cfd5a8882595e412f25de56f940ec9218ddd35d39f7d7"
1682dependencies = [ 1682dependencies = [
1683 "nom 8.0.0", 1683 "nom 8.0.0",
1684 "thiserror 2.0.18", 1684 "thiserror 2.0.18",
@@ -3024,9 +3024,9 @@ dependencies = [
3024 3024
3025[[package]] 3025[[package]]
3026name = "keybindings" 3026name = "keybindings"
3027version = "0.0.3" 3027version = "0.0.4"
3028source = "registry+https://github.com/rust-lang/crates.io-index" 3028source = "registry+https://github.com/rust-lang/crates.io-index"
3029checksum = "b0d60ff7a359bb81377b51a05068e04194dc4b7981fd95eea6c15201168e6bea" 3029checksum = "f5564033f75e66cfccdf9c33a8a409749d630b8cb3f7fe4c2991999229a0b64d"
3030dependencies = [ 3030dependencies = [
3031 "textwrap", 3031 "textwrap",
3032 "unicode-segmentation", 3032 "unicode-segmentation",
@@ -3713,9 +3713,9 @@ dependencies = [
3713 3713
3714[[package]] 3714[[package]]
3715name = "modalkit" 3715name = "modalkit"
3716version = "0.0.26" 3716version = "0.0.27"
3717source = "registry+https://github.com/rust-lang/crates.io-index" 3717source = "registry+https://github.com/rust-lang/crates.io-index"
3718checksum = "38edb029efaf2412b88180f6b94025989c40c532ab304c0c5f868d350413832c" 3718checksum = "de93aca188fc0e518c7c89782c3cb62ae4e14552398f2baaed9c5168b3ca1b3d"
3719dependencies = [ 3719dependencies = [
3720 "anymap2", 3720 "anymap2",
3721 "arboard", 3721 "arboard",
@@ -3737,9 +3737,9 @@ dependencies = [
3737 3737
3738[[package]] 3738[[package]]
3739name = "modalkit-ratatui" 3739name = "modalkit-ratatui"
3740version = "0.0.26" 3740version = "0.0.27"
3741source = "registry+https://github.com/rust-lang/crates.io-index" 3741source = "registry+https://github.com/rust-lang/crates.io-index"
3742checksum = "a9070725ef25a76d7dd3431c5ee4d108780dfc42d097d194d397721843b8ac30" 3742checksum = "cf64561c3f42a3a587d564fde9274fdbcf95287281efd56fc0db6a1c12459730"
3743dependencies = [ 3743dependencies = [
3744 "crossterm 0.29.0", 3744 "crossterm 0.29.0",
3745 "intervaltree", 3745 "intervaltree",
Cargo.toml +4 −4
@@ -81,15 +81,15 @@ version = "4.12"
81optional = true 81optional = true
82 82
83[dependencies.modalkit] 83[dependencies.modalkit]
84version = "0.0.26" 84version = "0.0.27"
85default-features = false 85default-features = false
86#git = "https://github.com/ulyssa/modalkit" 86#git = "https://github.com/ulyssa/modalkit"
87#rev = "ad12b9ba54dd1f022f54986931b5b1b358a6676d" 87#rev = "9386f6f75f6984a1cdbd7dddbb0c0bb3e7a37c5d"
88 88
89[dependencies.modalkit-ratatui] 89[dependencies.modalkit-ratatui]
90version = "0.0.26" 90version = "0.0.27"
91#git = "https://github.com/ulyssa/modalkit" 91#git = "https://github.com/ulyssa/modalkit"
92#rev = "ad12b9ba54dd1f022f54986931b5b1b358a6676d" 92#rev = "9386f6f75f6984a1cdbd7dddbb0c0bb3e7a37c5d"
93 93
94[dependencies.matrix-sdk-base] 94[dependencies.matrix-sdk-base]
95version = "0.18.0" 95version = "0.18.0"
config.example.toml +1
@@ -7,6 +7,7 @@ url = "https://matrix.org"
7 7
8[settings] 8[settings]
9default_markup = "html" 9default_markup = "html"
10default_register = "+"
10default_room = "#iamb-users:0x.badd.cafe" 11default_room = "#iamb-users:0x.badd.cafe"
11default_split = "vertical" 12default_split = "vertical"
12external_edit_file_suffix = ".md" 13external_edit_file_suffix = ".md"
docs/iamb.5 +7
@@ -139,6 +139,13 @@ Possible values are
139.Dq Sy markdown 139.Dq Sy markdown
140(the default) and 140(the default) and
141.Dq Sy plaintext . 141.Dq Sy plaintext .
142.It default_register
143The default register to read and write to when one isn't specified.
144This defaults to the unnamed register,
145.Sy " ,
146but you can set it to something like
147.Sy +
148if you want to read and write from the system clipboard by default.
142.It Sy default_room 149.It Sy default_room
143The room to show by default instead of the 150The room to show by default instead of the
144.Sy :welcome 151.Sy :welcome
src/config.rs +52
@@ -137,6 +137,35 @@ where
137 .transpose() 137 .transpose()
138} 138}
139 139
140fn deserialize_register<'de, D>(deserializer: D) -> Result<Option<Register>, D::Error>
141where
142 D: serde::de::Deserializer<'de>,
143{
144 let r = <&'de str>::deserialize(deserializer)?;
145
146 if r.len() > 1 {
147 return Err(D::Error::custom("expected a single character to specify a register"));
148 }
149
150 let r = match r.chars().next() {
151 Some(c @ 'a'..='z') => Register::Named(c),
152 Some('_') => Register::Blackhole,
153 Some('*') => Register::SelectionPrimary,
154 Some('+') => Register::SelectionClipboard,
155 Some('"') => Register::Unnamed,
156 Some(c) => {
157 return Err(D::Error::custom(format!(
158 "expected one of a-z, \", _, *, or + for the register, not {c:?}"
159 )));
160 },
161 None => {
162 return Err(D::Error::custom("expected a single character to specify a register"));
163 },
164 };
165
166 Ok(Some(r))
167}
168
140const VERSION: &str = match option_env!("VERGEN_GIT_SHA") { 169const VERSION: &str = match option_env!("VERGEN_GIT_SHA") {
141 None => env!("CARGO_PKG_VERSION"), 170 None => env!("CARGO_PKG_VERSION"),
142 Some(_) => concat!(env!("CARGO_PKG_VERSION"), " (", env!("VERGEN_GIT_SHA"), ")"), 171 Some(_) => concat!(env!("CARGO_PKG_VERSION"), " (", env!("VERGEN_GIT_SHA"), ")"),
@@ -807,6 +836,7 @@ pub struct TunableValues {
807 pub users: UserOverrides, 836 pub users: UserOverrides,
808 pub username_display: UserDisplayStyle, 837 pub username_display: UserDisplayStyle,
809 pub message_user_color: bool, 838 pub message_user_color: bool,
839 pub default_register: Option<Register>,
810 pub default_room: Option<String>, 840 pub default_room: Option<String>,
811 pub open_command: Option<Vec<String>>, 841 pub open_command: Option<Vec<String>>,
812 pub mouse: Mouse, 842 pub mouse: Mouse,
@@ -860,6 +890,8 @@ pub struct Tunables {
860 pub typing_notice_display: Option<bool>, 890 pub typing_notice_display: Option<bool>,
861 pub username_display: Option<UserDisplayStyle>, 891 pub username_display: Option<UserDisplayStyle>,
862 pub message_user_color: Option<bool>, 892 pub message_user_color: Option<bool>,
893 #[serde(default, deserialize_with = "deserialize_register")]
894 pub default_register: Option<Register>,
863 pub default_room: Option<String>, 895 pub default_room: Option<String>,
864 pub open_command: Option<Vec<String>>, 896 pub open_command: Option<Vec<String>>,
865 pub mouse: Option<Mouse>, 897 pub mouse: Option<Mouse>,
@@ -909,6 +941,7 @@ impl Tunables {
909 typing_notice_display: self.typing_notice_display.or(other.typing_notice_display), 941 typing_notice_display: self.typing_notice_display.or(other.typing_notice_display),
910 username_display: self.username_display.or(other.username_display), 942 username_display: self.username_display.or(other.username_display),
911 message_user_color: self.message_user_color.or(other.message_user_color), 943 message_user_color: self.message_user_color.or(other.message_user_color),
944 default_register: self.default_register.or(other.default_register),
912 default_room: self.default_room.or(other.default_room), 945 default_room: self.default_room.or(other.default_room),
913 open_command: self.open_command.or(other.open_command), 946 open_command: self.open_command.or(other.open_command),
914 mouse: self.mouse.or(other.mouse), 947 mouse: self.mouse.or(other.mouse),
@@ -952,6 +985,7 @@ impl Tunables {
952 typing_notice_display: self.typing_notice_display.unwrap_or(true), 985 typing_notice_display: self.typing_notice_display.unwrap_or(true),
953 username_display: self.username_display.unwrap_or_default(), 986 username_display: self.username_display.unwrap_or_default(),
954 message_user_color: self.message_user_color.unwrap_or(false), 987 message_user_color: self.message_user_color.unwrap_or(false),
988 default_register: self.default_register,
955 default_room: self.default_room, 989 default_room: self.default_room,
956 open_command: self.open_command, 990 open_command: self.open_command,
957 mouse: self.mouse.unwrap_or_default(), 991 mouse: self.mouse.unwrap_or_default(),
@@ -1634,6 +1668,24 @@ mod tests {
1634 assert_eq!(merged.proxy.headers.is_empty(), true); 1668 assert_eq!(merged.proxy.headers.is_empty(), true);
1635 } 1669 }
1636 1670
1671 #[test]
1672 fn test_parse_tunables_default_register() {
1673 let reg_a: Tunables = serde_json::from_str(r#"{"default_register": "a"}"#).unwrap();
1674 assert_eq!(reg_a.default_register, Some(Register::Named('a')));
1675
1676 let reg_z: Tunables = serde_json::from_str(r#"{"default_register": "z"}"#).unwrap();
1677 assert_eq!(reg_z.default_register, Some(Register::Named('z')));
1678
1679 let reg_blackhole: Tunables = serde_json::from_str(r#"{"default_register": "_"}"#).unwrap();
1680 assert_eq!(reg_blackhole.default_register, Some(Register::Blackhole));
1681
1682 let res: Result<Tunables, _> = serde_json::from_str(r#"{"default_register": "A"}"#);
1683 assert!(res.is_err());
1684
1685 let res: Result<Tunables, _> = serde_json::from_str(r#"{"default_register": "0"}"#);
1686 assert!(res.is_err());
1687 }
1688
1637 #[test] 1689 #[test]
1638 fn test_parse_layout() { 1690 fn test_parse_layout() {
1639 let user = WindowPath::UserId(user_id!("@user:example.com").to_owned()); 1691 let user = WindowPath::UserId(user_id!("@user:example.com").to_owned());
src/main.rs +5
@@ -1051,6 +1051,11 @@ async fn run(settings: ApplicationSettings) -> IambResult<()> {
1051 let mut store = Store::new(store); 1051 let mut store = Store::new(store);
1052 store.completer = Box::new(IambCompleter); 1052 store.completer = Box::new(IambCompleter);
1053 1053
1054 if let Some(r) = store.application.settings.tunables.default_register.as_ref() {
1055 // Set the RegisterStore to use the user's default register:
1056 store.registers.set_default_register(r.clone());
1057 }
1058
1054 let store = Arc::new(AsyncMutex::new(store)); 1059 let store = Arc::new(AsyncMutex::new(store));
1055 worker.init(store.clone()); 1060 worker.init(store.clone());
1056 1061
src/tests.rs +1
@@ -150,6 +150,7 @@ pub fn mock_tunables() -> TunableValues {
150 TunableValues { 150 TunableValues {
151 default_markup: Default::default(), 151 default_markup: Default::default(),
152 ignorecase: false, 152 ignorecase: false,
153 default_register: None,
153 default_room: None, 154 default_room: None,
154 encryption: Encryption::default().values(), 155 encryption: Encryption::default().values(),
155 input_prompt: None, 156 input_prompt: None,