Skip to content

Commit 5744dd3

Browse files
fix: repair ascii-prefixed layout tails
1 parent 68979cb commit 5744dd3

9 files changed

Lines changed: 51 additions & 11 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lay"
3-
version = "0.1.206"
3+
version = "0.1.207"
44
edition = "2021"
55
description = "Alpha Double Shift RU/EN layout rescue for Linux desktops"
66
license = "MIT"

VERSIONING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ number from `git rev-list`.
1313

1414
Current publication branch version:
1515

16-
- `0.1.202`
16+
- `0.1.207`
1717

1818
Do not rely on commit counts. Before publishing or pushing, run the bump script
1919
or verify the version fields manually.

extension/lay@radislabus-star.github.io/lay-impl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ const STATS_PATH = GLib.get_home_dir() + '/.local/share/lay/stats.json';
2222
const RECENT_ACTIONS_PATH = GLib.get_home_dir() + '/.local/share/lay/recent_actions.jsonl';
2323
const PROJECT_DIR = GLib.get_home_dir() + '/projects/lay';
2424
const UPDATE_LOG_PATH = GLib.get_home_dir() + '/.local/state/lay/update.log';
25-
const APP_VERSION = '0.1.206';
25+
const APP_VERSION = '0.1.207';
2626
const APP_DESCRIPTION = 'Alpha RU/EN layout helper: double Shift и помощь при наборе';
27-
const APP_RELEASE_DATE = '2026-06-01';
27+
const APP_RELEASE_DATE = '2026-06-03';
2828
const APP_LICENSE = 'MIT';
2929
const APP_URL = 'https://github.com/radislabus-star/lay-public';
3030
const APP_PLATFORM = 'Linux desktops: GNOME, KDE, Wayland, X11';

extension/lay@radislabus-star.github.io/metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"uuid": "lay@radislabus-star.github.io",
33
"name": "Lay Layout Switcher",
4-
"version": 206,
5-
"version-name": "0.1.206",
4+
"version": 207,
5+
"version-name": "0.1.207",
66
"description": "Alpha GNOME Shell extension для lay-daemon. Показывает EN/RU в трее, переключает раскладку по клику. Минимальный DBus bridge для layout activation и fallback text insert.",
77
"shell-version": ["45", "46", "47", "50"],
88
"url": "https://github.com/radislabus-star/lay-public"

src/layout_autoswitch/technical.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//! Technical-token layout corrections.
22
33
use crate::keyboard::is_cyrillic_letter;
4-
use crate::word_recognizer::is_ascii_technical_token;
4+
use crate::token_language::is_known_ru_token;
5+
use crate::word_recognizer::{
6+
is_ascii_technical_or_brand_token, is_ascii_technical_token, is_upper_ascii_acronym,
7+
};
58

69
use super::hyphen::{
710
has_known_cyrillic_hyphen_fragment, is_cyrillic_hyphenated_word_for_layout,
@@ -36,6 +39,10 @@ pub fn correct_duplicate_layout_prefix_on_ascii_token(token: &str) -> Option<Str
3639
}
3740

3841
pub fn correct_wrong_layout_ascii_technical_token(token: &str) -> Option<String> {
42+
if let Some(repaired) = correct_ascii_prefix_with_ru_layout_tail(token) {
43+
return Some(repaired);
44+
}
45+
3946
if !token.contains('-') || !is_plain_cyrillic_technical_source(token) {
4047
return None;
4148
}
@@ -63,6 +70,33 @@ pub fn correct_wrong_layout_ascii_technical_token(token: &str) -> Option<String>
6370
}
6471
}
6572

73+
fn correct_ascii_prefix_with_ru_layout_tail(token: &str) -> Option<String> {
74+
let (prefix, tail) = token.split_once('-')?;
75+
if prefix.is_empty()
76+
|| tail.is_empty()
77+
|| tail.contains('-')
78+
|| !tail.chars().all(|ch| ch.is_ascii_alphabetic())
79+
{
80+
return None;
81+
}
82+
if !is_ascii_layout_anchor(prefix) {
83+
return None;
84+
}
85+
86+
let converted_tail = crate::dict::convert(tail, crate::dict::Direction::Us2Ru);
87+
if converted_tail == tail || !is_known_ru_token(&converted_tail) {
88+
return None;
89+
}
90+
91+
Some(format!("{prefix}-{converted_tail}"))
92+
}
93+
94+
fn is_ascii_layout_anchor(prefix: &str) -> bool {
95+
prefix.is_ascii()
96+
&& prefix.chars().any(|ch| ch.is_ascii_alphabetic())
97+
&& (is_upper_ascii_acronym(prefix) || is_ascii_technical_or_brand_token(prefix))
98+
}
99+
66100
pub fn should_keep_plain_cyrillic_before_ascii_technical(original: &str, converted: &str) -> bool {
67101
original.chars().count() >= 4
68102
&& original.chars().all(is_cyrillic_letter)

src/typing_candidate/scoring.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,12 @@ fn language_delta(text: &CandidateTextPair<'_>) -> f64 {
112112
if !text.has_cyrillic() {
113113
return 0.0;
114114
}
115-
crate::ngram::ru_candidate_margin(text.replacement, text.original)
116-
.clamp(LANGUAGE_MARGIN_MIN, LANGUAGE_MARGIN_MAX)
117-
* LANGUAGE_MARGIN_WEIGHT
115+
let margin = crate::ngram::ru_candidate_margin(text.replacement, text.original);
116+
if !margin.is_finite() {
117+
return 0.0;
118+
}
119+
120+
margin.clamp(LANGUAGE_MARGIN_MIN, LANGUAGE_MARGIN_MAX) * LANGUAGE_MARGIN_WEIGHT
118121
}
119122

120123
fn structure_bonus(text: &CandidateTextPair<'_>) -> f64 {

src/typing_candidate_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ fn score_components_are_finite_for_edge_inputs() {
8686
("word", "", -1),
8787
("словослитно ", "слово слитно ", 100),
8888
("ошисбя", "ошибся", 130),
89+
("QR-rjlf", "QR-кода", 80),
8990
] {
9091
let score = score_typing_candidate(original, replacement, "missing_letter", priority);
9192
assert!(score.total.is_finite(), "total must be finite: {score:?}");

tests/fixtures/daemon_typing_assist_technical_hyphen_token.tsv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
из-за None
33
цш-аш wi-fi
44
15р-16р None
5+
QR-rjlf QR-кода
6+
QR-rjls QR-коды

0 commit comments

Comments
 (0)