Skip to content

Commit adb0d32

Browse files
Fix the bugs
1 parent 48b8c73 commit adb0d32

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

crates/editor/src/editor.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,7 @@ impl Editor {
21932193
let editor_id = cx.entity().entity_id().as_u64() as ItemId;
21942194
let snapshot = self.buffer().read(cx).snapshot(cx);
21952195
self.serialize_selections = cx.background_spawn(async move {
2196-
background_executor.timer(UPDATE_DEBOUNCE).await;
2196+
background_executor.timer(Duration::from_millis(100)).await;
21972197
let selections = selections
21982198
.iter()
21992199
.map(|selection| {
@@ -14906,7 +14906,8 @@ impl Editor {
1490614906
self.load_diff_task.clone()
1490714907
}
1490814908

14909-
// TODO kb allow to turn it off in the settings
14909+
// TODO kb allow to turn it off in the settings.
14910+
// TODO kb does not work when keeping the editor open, and close && go back the same editor.
1491014911
fn read_selections_from_db(
1491114912
&mut self,
1491214913
item_id: u64,
@@ -14917,6 +14918,9 @@ impl Editor {
1491714918
let Some(selections) = DB.get_editor_selections(item_id, workspace_id).log_err() else {
1491814919
return;
1491914920
};
14921+
if selections.is_empty() {
14922+
return;
14923+
}
1492014924

1492114925
self.change_selections(None, window, cx, |s| {
1492214926
s.select_ranges(selections.into_iter().map(|(start, end)| start..end));

crates/editor/src/persistence.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ define_connection!(
144144
end INTEGER NOT NULL,
145145
PRIMARY KEY(item_id),
146146
FOREIGN KEY(editor_id, workspace_id) REFERENCES editors(item_id, workspace_id)
147+
ON DELETE CASCADE
147148
) STRICT;
148149
),
149150
];
@@ -211,8 +212,8 @@ impl EditorDb {
211212
workspace_id: WorkspaceId
212213
) -> Result<Vec<(usize, usize)>> {
213214
SELECT start, end
214-
FROM selections
215-
WHERE item_id = ?1 AND workspace_id = ?2
215+
FROM editor_selections
216+
WHERE editor_id = ?1 AND workspace_id = ?2
216217
}
217218
}
218219

@@ -224,7 +225,7 @@ impl EditorDb {
224225
) -> Result<()> {
225226
let mut first_selection;
226227
let mut last_selection = 0_usize;
227-
for (count, placeholders) in std::iter::once("(?, ?, ?, ?)")
228+
for (count, placeholders) in std::iter::once("(?1, ?2, ?, ?)")
228229
.cycle()
229230
.take(selections.len())
230231
.chunks(MAX_QUERY_PLACEHOLDERS / 4)
@@ -244,16 +245,11 @@ impl EditorDb {
244245
last_selection = last_selection + count;
245246
let query = format!(
246247
r#"
247-
BEGIN TRANSACTION;
248-
249-
DELETE FROM editor_selections WHERE item_id = ?1 AND workspace_id = ?2;
250-
251-
INSERT INTO selections (item_id, workspace_id, start, end)
252-
VALUES ({placeholders});
253-
254-
COMMIT;
248+
DELETE FROM editor_selections WHERE editor_id = ?1 AND workspace_id = ?2;
255249
256-
DELETE FROM editors WHERE workspace_id = ? AND item_id NOT IN ({placeholders})"#
250+
INSERT INTO editor_selections (editor_id, workspace_id, start, end)
251+
VALUES {placeholders};
252+
"#
257253
);
258254

259255
let selections = selections[first_selection..last_selection].to_vec();
@@ -262,8 +258,6 @@ impl EditorDb {
262258
statement.bind(&editor_id, 1)?;
263259
let mut next_index = statement.bind(&workspace_id, 2)?;
264260
for (start, end) in selections {
265-
next_index = statement.bind(&editor_id, next_index)?;
266-
next_index = statement.bind(&workspace_id, next_index)?;
267261
next_index = statement.bind(&start, next_index)?;
268262
next_index = statement.bind(&end, next_index)?;
269263
}

0 commit comments

Comments
 (0)