Add simple IME handling to the terminal
This commit is contained in:
parent
6d264502b2
commit
0185b4fef4
5 changed files with 25 additions and 50 deletions
|
@ -1713,6 +1713,13 @@ impl Cursor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn bounding_rect(&self, origin: Vector2F) -> RectF {
|
||||||
|
RectF::new(
|
||||||
|
self.origin + origin,
|
||||||
|
vec2f(self.block_width, self.line_height),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn paint(&self, origin: Vector2F, cx: &mut PaintContext) {
|
pub fn paint(&self, origin: Vector2F, cx: &mut PaintContext) {
|
||||||
let bounds = match self.shape {
|
let bounds = match self.shape {
|
||||||
CursorShape::Bar => RectF::new(self.origin + origin, vec2f(2.0, self.line_height)),
|
CursorShape::Bar => RectF::new(self.origin + origin, vec2f(2.0, self.line_height)),
|
||||||
|
|
|
@ -240,53 +240,7 @@ pub fn to_esc_str(keystroke: &Keystroke, mode: &TermMode) -> Option<String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Fallback to sending the keystroke input directly
|
|
||||||
//Skin colors in utf8 are implemented as a seperate, invisible character
|
|
||||||
//that modifies the associated emoji. Some languages may have similarly
|
|
||||||
//implemented modifiers, e.g. certain diacritics that can be typed as a single character.
|
|
||||||
//This means that we need to assume some user input can result in multi-byte,
|
|
||||||
//multi-char strings. This is somewhat difficult, as GPUI normalizes all
|
|
||||||
//keys into a string representation. Hence, the check here to filter out GPUI
|
|
||||||
//keys that weren't captured above.
|
|
||||||
if !matches_gpui_key_str(&keystroke.key) {
|
|
||||||
return Some(keystroke.key.clone());
|
|
||||||
} else {
|
|
||||||
None
|
None
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///Checks if the given string matches a GPUI key string.
|
|
||||||
///Table made from reading the source at gpui/src/platform/mac/event.rs
|
|
||||||
fn matches_gpui_key_str(str: &str) -> bool {
|
|
||||||
match str {
|
|
||||||
"backspace" => true,
|
|
||||||
"up" => true,
|
|
||||||
"down" => true,
|
|
||||||
"left" => true,
|
|
||||||
"right" => true,
|
|
||||||
"pageup" => true,
|
|
||||||
"pagedown" => true,
|
|
||||||
"home" => true,
|
|
||||||
"end" => true,
|
|
||||||
"delete" => true,
|
|
||||||
"enter" => true,
|
|
||||||
"escape" => true,
|
|
||||||
"tab" => true,
|
|
||||||
"f1" => true,
|
|
||||||
"f2" => true,
|
|
||||||
"f3" => true,
|
|
||||||
"f4" => true,
|
|
||||||
"f5" => true,
|
|
||||||
"f6" => true,
|
|
||||||
"f7" => true,
|
|
||||||
"f8" => true,
|
|
||||||
"f9" => true,
|
|
||||||
"f10" => true,
|
|
||||||
"f11" => true,
|
|
||||||
"f12" => true,
|
|
||||||
"space" => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Code Modifiers
|
/// Code Modifiers
|
||||||
|
|
|
@ -262,6 +262,10 @@ impl View for Terminal {
|
||||||
context
|
context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn selected_text_range(&self, _: &AppContext) -> Option<std::ops::Range<usize>> {
|
||||||
|
Some(0..0)
|
||||||
|
}
|
||||||
|
|
||||||
fn replace_text_in_range(
|
fn replace_text_in_range(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: Option<std::ops::Range<usize>>,
|
_: Option<std::ops::Range<usize>>,
|
||||||
|
|
|
@ -398,13 +398,22 @@ impl Element for TerminalEl {
|
||||||
fn rect_for_text_range(
|
fn rect_for_text_range(
|
||||||
&self,
|
&self,
|
||||||
_: Range<usize>,
|
_: Range<usize>,
|
||||||
|
bounds: RectF,
|
||||||
_: RectF,
|
_: RectF,
|
||||||
_: RectF,
|
layout: &Self::LayoutState,
|
||||||
_: &Self::LayoutState,
|
|
||||||
_: &Self::PaintState,
|
_: &Self::PaintState,
|
||||||
_: &gpui::MeasurementContext,
|
_: &gpui::MeasurementContext,
|
||||||
) -> Option<RectF> {
|
) -> Option<RectF> {
|
||||||
todo!()
|
// Use the same origin that's passed to `Cursor::paint` in the paint
|
||||||
|
// method bove.
|
||||||
|
let mut origin = bounds.origin() + vec2f(layout.em_width.0, 0.);
|
||||||
|
|
||||||
|
// TODO - Why is it necessary to move downward one line to get correct
|
||||||
|
// positioning? I would think that we'd want the same rect that is
|
||||||
|
// painted for the cursor.
|
||||||
|
origin += vec2f(0., layout.line_height.0);
|
||||||
|
|
||||||
|
Some(layout.cursor.as_ref()?.bounding_rect(origin))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn debug(
|
fn debug(
|
||||||
|
|
1
styles/package-lock.json
generated
1
styles/package-lock.json
generated
|
@ -5,6 +5,7 @@
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
|
"name": "styles",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue