Skip to content

Commit 5163c56

Browse files
authored
fix(render): 修正渲染缓冲区中多字节字符处理逻辑 (#39)
* fix(render): 修正渲染缓冲区中多字节字符处理逻辑 将字符长度计算方式改为基于grapheme clusters,并添加边界检查防止越界。 Signed-off-by: longjin <longjin@DragonOS.org> * refactor: 清理未使用的导入语句 移除多个文件中未使用的导入语句,优化代码结构。 Signed-off-by: longjin <longjin@DragonOS.org> --------- Signed-off-by: longjin <longjin@DragonOS.org>
1 parent cfb11d4 commit 5163c56

File tree

9 files changed

+8
-21
lines changed

9 files changed

+8
-21
lines changed

held_core/src/interface/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{get_application, APPLICATION};
1+
use super::get_application;
22

33
pub trait App {
44
fn exit(&mut self);

held_core/src/view/render/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::str::Chars;
2-
31
use cell::Cell;
42

53
use crate::utils::{position::Position, rectangle::Rectangle};

src/application/handler/app.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::application::mode::command::CommandData;
21
use crate::application::mode::{ModeData, ModeKey};
32
use crate::application::Application;
43
use crate::errors::*;

src/application/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use mode::{
1212
use smallvec::SmallVec;
1313
use state::ApplicationStateData;
1414

15-
use std::{cell::RefCell, collections::HashMap, mem, rc::Rc, sync::Arc};
15+
use std::{cell::RefCell, collections::HashMap, mem, rc::Rc};
1616

1717
use crate::{
1818
modules::perferences::{Perferences, PerferencesManager},

src/application/mode/command.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::{collections::HashMap, process::CommandArgs};
2-
31
use held_core::{
42
utils::position::Position,
53
view::{colors::Colors, style::CharStyle},

src/modules/perferences/yaml.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
use std::path::PathBuf;
2-
3-
use super::{
4-
Perferences, APP_INFO, LINE_WRAPPING_KEY, SOFT_TAB_KEY, TAB_WIDTH_KEY, THEME_KET, THEME_PATH,
5-
};
6-
use crate::{
7-
errors::*,
8-
modules::perferences::{LANGUAGE_KEY, LANGUAGE_SYNTAX_KEY, SYNTAX_PATH},
9-
};
10-
use app_dirs2::{app_dir, AppDataType};
1+
use super::{Perferences, LINE_WRAPPING_KEY, SOFT_TAB_KEY, TAB_WIDTH_KEY, THEME_KET};
2+
use crate::modules::perferences::{LANGUAGE_KEY, LANGUAGE_SYNTAX_KEY};
113
use yaml_rust::Yaml;
124

135
pub struct YamlPerferences {

src/view/presenter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{borrow::Cow, cell::RefCell, fmt::Debug, rc::Rc};
1+
use std::{borrow::Cow, fmt::Debug};
22

33
use super::{
44
colors::map::ColorMap,

src/view/render/render_buffer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ impl CachedRenderBuffer {
5959

6060
if !equal {
6161
let mut cache_cell = CachedCell::default();
62-
let content_len = cell_content.len();
62+
let grapheme_count = cell.content.graphemes(true).count().max(1);
6363
cache_cell.colors = cell.colors;
6464
cache_cell.style = cell.style;
6565
cache_cell.content = cell_content;
66-
for i in (index + 1)..(index + content_len) {
66+
let end_index = (index + grapheme_count).min(self.cells.len());
67+
for i in (index + 1)..end_index {
6768
self.cells[i] = None
6869
}
6970

src/workspace.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ impl Workspace {
190190
.or_else(|| Some(self.syntax_set.find_syntax_plain_text()))
191191
.cloned();
192192

193-
drop(buffer);
194193
self.get_buffer_mut(id)
195194
.ok_or(ErrorKind::EmptyWorkspace)?
196195
.syntax_definition = definition;

0 commit comments

Comments
 (0)