mirror of
https://github.com/danbulant/cushy
synced 2026-06-24 17:12:11 +00:00
Fixing password field clicking
This commit is contained in:
parent
7992887a85
commit
ca58cb5fcf
2 changed files with 28 additions and 7 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -623,7 +623,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "figures"
|
name = "figures"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/khonsulabs/figures#0745fc0ff95e94ce2181aa1528a30bda3d6152f2"
|
source = "git+https://github.com/khonsulabs/figures#40045fa1940f6212bc4876a4ef9ae2cd0bd89808"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"euclid",
|
"euclid",
|
||||||
|
|
@ -1089,7 +1089,7 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kludgine"
|
name = "kludgine"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/khonsulabs/kludgine#f286d7de3f37ec7430890f6eeeb5d98a1ff0314e"
|
source = "git+https://github.com/khonsulabs/kludgine#6b56d6524a8843f9a1a598e4d344407798971732"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
"alot",
|
"alot",
|
||||||
|
|
|
||||||
|
|
@ -496,8 +496,10 @@ where
|
||||||
if mask_bytes > 0 {
|
if mask_bytes > 0 {
|
||||||
self.value.map_ref(|value| {
|
self.value.map_ref(|value| {
|
||||||
let value = value.as_str();
|
let value = value.as_str();
|
||||||
|
assert!(cursor.offset <= value.len());
|
||||||
cursor.offset = value[..cursor.offset].graphemes(true).count() * mask_bytes;
|
cursor.offset = value[..cursor.offset].graphemes(true).count() * mask_bytes;
|
||||||
if let Some(selection) = &mut selection {
|
if let Some(selection) = &mut selection {
|
||||||
|
assert!(selection.offset <= value.len());
|
||||||
selection.offset =
|
selection.offset =
|
||||||
value[..selection.offset].graphemes(true).count() * mask_bytes;
|
value[..selection.offset].graphemes(true).count() * mask_bytes;
|
||||||
}
|
}
|
||||||
|
|
@ -652,18 +654,37 @@ where
|
||||||
&mut self,
|
&mut self,
|
||||||
location: Point<Px>,
|
location: Point<Px>,
|
||||||
context: &mut EventContext<'_, '_>,
|
context: &mut EventContext<'_, '_>,
|
||||||
|
) -> Cursor {
|
||||||
|
let mut cursor = self.cached_cursor_from_point(location, context);
|
||||||
|
if let Some(symbol) = self.mask.graphemes(true).next() {
|
||||||
|
let grapheme_offset = cursor.offset / symbol.len();
|
||||||
|
cursor.offset = self.value.map_ref(|value| {
|
||||||
|
value
|
||||||
|
.as_str()
|
||||||
|
.graphemes(true)
|
||||||
|
.take(grapheme_offset)
|
||||||
|
.map(str::len)
|
||||||
|
.sum::<usize>()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
cursor
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cached_cursor_from_point(
|
||||||
|
&mut self,
|
||||||
|
location: Point<Px>,
|
||||||
|
context: &mut EventContext<'_, '_>,
|
||||||
) -> Cursor {
|
) -> Cursor {
|
||||||
let Some(cache) = &self.cache else {
|
let Some(cache) = &self.cache else {
|
||||||
return Cursor::default();
|
return Cursor::default();
|
||||||
};
|
};
|
||||||
|
|
||||||
let text_length = self.value.map_ref(|value| value.as_str().len());
|
|
||||||
let padding = context
|
let padding = context
|
||||||
.get(&IntrinsicPadding)
|
.get(&IntrinsicPadding)
|
||||||
.into_px(context.kludgine.scale());
|
.into_px(context.kludgine.scale());
|
||||||
let location = location - padding;
|
let mut location = location - padding;
|
||||||
if location.y < 0 {
|
if location.y < 0 {
|
||||||
return Cursor::default();
|
location.y = Px::ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut closest: Option<(Cursor, i32)> = None;
|
let mut closest: Option<(Cursor, i32)> = None;
|
||||||
|
|
@ -686,7 +707,7 @@ where
|
||||||
&& relative.y < cache.measured.line_height
|
&& relative.y < cache.measured.line_height
|
||||||
{
|
{
|
||||||
return if relative.x > rect.size.width / 2 {
|
return if relative.x > rect.size.width / 2 {
|
||||||
if glyph.info.start + 1 < text_length {
|
if glyph.info.start + 1 < cache.bytes {
|
||||||
Cursor {
|
Cursor {
|
||||||
offset: glyph.info.start + 1,
|
offset: glyph.info.start + 1,
|
||||||
affinity: Affinity::Before,
|
affinity: Affinity::Before,
|
||||||
|
|
@ -730,7 +751,7 @@ where
|
||||||
closest
|
closest
|
||||||
} else {
|
} else {
|
||||||
Cursor {
|
Cursor {
|
||||||
offset: text_length,
|
offset: cache.bytes,
|
||||||
affinity: Affinity::After,
|
affinity: Affinity::After,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue