|
|
|
@ -1034,7 +1034,12 @@ impl Document {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Apply a [`Transaction`] to the [`Document`] to change its text.
|
|
|
|
|
fn apply_impl(&mut self, transaction: &Transaction, view_id: ViewId) -> bool {
|
|
|
|
|
fn apply_impl(
|
|
|
|
|
&mut self,
|
|
|
|
|
transaction: &Transaction,
|
|
|
|
|
view_id: ViewId,
|
|
|
|
|
emit_lsp_notification: bool,
|
|
|
|
|
) -> bool {
|
|
|
|
|
use helix_core::Assoc;
|
|
|
|
|
|
|
|
|
|
let old_doc = self.text().clone();
|
|
|
|
@ -1130,25 +1135,31 @@ impl Document {
|
|
|
|
|
apply_inlay_hint_changes(padding_after_inlay_hints);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// emit lsp notification
|
|
|
|
|
if let Some(language_server) = self.language_server() {
|
|
|
|
|
let notify = language_server.text_document_did_change(
|
|
|
|
|
self.versioned_identifier(),
|
|
|
|
|
&old_doc,
|
|
|
|
|
self.text(),
|
|
|
|
|
changes,
|
|
|
|
|
);
|
|
|
|
|
if emit_lsp_notification {
|
|
|
|
|
// emit lsp notification
|
|
|
|
|
if let Some(language_server) = self.language_server() {
|
|
|
|
|
let notify = language_server.text_document_did_change(
|
|
|
|
|
self.versioned_identifier(),
|
|
|
|
|
&old_doc,
|
|
|
|
|
self.text(),
|
|
|
|
|
changes,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if let Some(notify) = notify {
|
|
|
|
|
tokio::spawn(notify);
|
|
|
|
|
if let Some(notify) = notify {
|
|
|
|
|
tokio::spawn(notify);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
success
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Apply a [`Transaction`] to the [`Document`] to change its text.
|
|
|
|
|
pub fn apply(&mut self, transaction: &Transaction, view_id: ViewId) -> bool {
|
|
|
|
|
fn apply_inner(
|
|
|
|
|
&mut self,
|
|
|
|
|
transaction: &Transaction,
|
|
|
|
|
view_id: ViewId,
|
|
|
|
|
emit_lsp_notification: bool,
|
|
|
|
|
) -> bool {
|
|
|
|
|
// store the state just before any changes are made. This allows us to undo to the
|
|
|
|
|
// state just before a transaction was applied.
|
|
|
|
|
if self.changes.is_empty() && !transaction.changes().is_empty() {
|
|
|
|
@ -1158,7 +1169,7 @@ impl Document {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let success = self.apply_impl(transaction, view_id);
|
|
|
|
|
let success = self.apply_impl(transaction, view_id, emit_lsp_notification);
|
|
|
|
|
|
|
|
|
|
if !transaction.changes().is_empty() {
|
|
|
|
|
// Compose this transaction with the previous one
|
|
|
|
@ -1168,12 +1179,23 @@ impl Document {
|
|
|
|
|
}
|
|
|
|
|
success
|
|
|
|
|
}
|
|
|
|
|
/// Apply a [`Transaction`] to the [`Document`] to change its text.
|
|
|
|
|
pub fn apply(&mut self, transaction: &Transaction, view_id: ViewId) -> bool {
|
|
|
|
|
self.apply_inner(transaction, view_id, true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Apply a [`Transaction`] to the [`Document`] to change its text.
|
|
|
|
|
/// without notifying the language servers. This is useful for temporary transactions
|
|
|
|
|
/// that must not influence the server.
|
|
|
|
|
pub fn apply_temporary(&mut self, transaction: &Transaction, view_id: ViewId) -> bool {
|
|
|
|
|
self.apply_inner(transaction, view_id, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn undo_redo_impl(&mut self, view: &mut View, undo: bool) -> bool {
|
|
|
|
|
let mut history = self.history.take();
|
|
|
|
|
let txn = if undo { history.undo() } else { history.redo() };
|
|
|
|
|
let success = if let Some(txn) = txn {
|
|
|
|
|
self.apply_impl(txn, view.id)
|
|
|
|
|
self.apply_impl(txn, view.id, true)
|
|
|
|
|
} else {
|
|
|
|
|
false
|
|
|
|
|
};
|
|
|
|
@ -1213,7 +1235,7 @@ impl Document {
|
|
|
|
|
savepoint
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn restore(&mut self, view: &mut View, savepoint: &SavePoint) {
|
|
|
|
|
pub fn restore(&mut self, view: &mut View, savepoint: &SavePoint, emit_lsp_notification: bool) {
|
|
|
|
|
assert_eq!(
|
|
|
|
|
savepoint.view, view.id,
|
|
|
|
|
"Savepoint must not be used with a different view!"
|
|
|
|
@ -1228,7 +1250,7 @@ impl Document {
|
|
|
|
|
|
|
|
|
|
let savepoint_ref = self.savepoints.remove(savepoint_idx);
|
|
|
|
|
let mut revert = savepoint.revert.lock();
|
|
|
|
|
self.apply(&revert, view.id);
|
|
|
|
|
self.apply_inner(&revert, view.id, emit_lsp_notification);
|
|
|
|
|
*revert = Transaction::new(self.text()).with_selection(self.selection(view.id).clone());
|
|
|
|
|
self.savepoints.push(savepoint_ref)
|
|
|
|
|
}
|
|
|
|
@ -1241,7 +1263,7 @@ impl Document {
|
|
|
|
|
};
|
|
|
|
|
let mut success = false;
|
|
|
|
|
for txn in txns {
|
|
|
|
|
if self.apply_impl(&txn, view.id) {
|
|
|
|
|
if self.apply_impl(&txn, view.id, true) {
|
|
|
|
|
success = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|