Compare commits

...

3 Commits

Author SHA1 Message Date
Conrad Irwin
845249c6ed Clippppppppppppppy 2024-06-26 22:14:37 -06:00
Conrad Irwin
da18afdd24 testing changes 2024-06-26 21:53:00 -06:00
Conrad Irwin
6f04b890a9 Fix font fallbacks in cosmic text
The entire font fallback stack has Stretch: Normal, but "Zed Mono" and
"Zed Sans" have Strech: Expanded. This allows us to fallback to CJK
fonts as needed.

A better solution would be to work with fontdb for this instead, as
the cosmic text fallbacks don't respect monospacedness (nor user
preference).
2024-06-26 21:47:42 -06:00
2 changed files with 38 additions and 3 deletions

View File

@@ -15,7 +15,9 @@ actions!(
SelectAll,
Home,
End,
ShowCharacterPalette
ShowCharacterPalette,
Copy,
Paste
]
);
@@ -80,6 +82,20 @@ impl TextInput {
self.replace_text_in_range(None, "", cx)
}
fn copy(&mut self, _: &crate::Copy, cx: &mut ViewContext<Self>) {
if self.selected_range.is_empty() {
return;
}
let selected_text = &self.content[self.selected_range.clone()];
cx.write_to_clipboard(ClipboardItem::new(selected_text.to_string()));
}
fn paste(&mut self, _: &Paste, cx: &mut ViewContext<Self>) {
if let Some(item) = cx.read_from_clipboard() {
self.replace_text_in_range(None, &item.text().replace('\n', ""), cx);
}
}
fn show_character_palette(&mut self, _: &ShowCharacterPalette, cx: &mut ViewContext<Self>) {
cx.show_character_palette();
}
@@ -429,6 +445,9 @@ impl Render for TextInput {
.on_action(cx.listener(Self::home))
.on_action(cx.listener(Self::end))
.on_action(cx.listener(Self::show_character_palette))
.on_action(cx.listener(Self::paste))
.on_action(cx.listener(Self::copy))
.font_family("Zed Mono")
.bg(rgb(0xeeeeee))
.size_full()
.line_height(px(30.))
@@ -447,8 +466,19 @@ impl Render for TextInput {
}
fn main() {
env_logger::Builder::new().parse_default_env().init();
App::new().run(|cx: &mut AppContext| {
let bounds = Bounds::centered(None, size(px(300.0), px(300.0)), cx);
let fonts = vec![
std::fs::read("assets/fonts/zed-mono/zed-mono-extended.ttf")
.unwrap()
.into(),
std::fs::read("assets/fonts/zed-sans/zed-sans-extended.ttf")
.unwrap()
.into(),
];
cx.text_system().add_fonts(fonts).unwrap();
cx.bind_keys([
KeyBinding::new("backspace", Backspace, None),
KeyBinding::new("delete", Delete, None),
@@ -457,9 +487,15 @@ fn main() {
KeyBinding::new("shift-left", SelectLeft, None),
KeyBinding::new("shift-right", SelectRight, None),
KeyBinding::new("cmd-a", SelectAll, None),
KeyBinding::new("cmd-c", Copy, None),
KeyBinding::new("cmd-v", Paste, None),
KeyBinding::new("home", Home, None),
KeyBinding::new("end", End, None),
KeyBinding::new("ctrl-cmd-space", ShowCharacterPalette, None),
KeyBinding::new("ctrl-a", SelectAll, None),
KeyBinding::new("ctrl-c", Copy, None),
KeyBinding::new("ctrl-v", Paste, None),
KeyBinding::new("ctrl-.", ShowCharacterPalette, None),
]);
let window = cx
.open_window(
@@ -470,7 +506,7 @@ fn main() {
|cx| {
cx.new_view(|cx| TextInput {
focus_handle: cx.focus_handle(),
content: "".into(),
content: "aチ".into(),
selected_range: 0..0,
selection_reversed: false,
marked_range: None,

View File

@@ -379,7 +379,6 @@ impl CosmicTextSystemState {
offs..(offs + run.len),
Attrs::new()
.family(Family::Name(&font.families.first().unwrap().0))
.stretch(font.stretch)
.style(font.style)
.weight(font.weight),
);