aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/document.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-11-21 11:06:45 +0000
committerBlaž Hrastnik2021-11-21 11:06:45 +0000
commitd1854d8e6af07cd78ab6c24c859a4471afb3514e (patch)
tree301e4212e7fc88dd5f626f884bd78b700cf3e4a6 /helix-view/src/document.rs
parent8b85903116fdfdc177bf2ca171831674144de70a (diff)
parentb95c9470de9f9199f109fdbfb6ec9a951fbe8866 (diff)
Merge remote-tracking branch 'origin/master' into debug
Diffstat (limited to 'helix-view/src/document.rs')
-rw-r--r--helix-view/src/document.rs32
1 files changed, 26 insertions, 6 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index ce5df8ee..76b19a07 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -25,6 +25,8 @@ const BUF_SIZE: usize = 8192;
const DEFAULT_INDENT: IndentStyle = IndentStyle::Spaces(4);
+pub const SCRATCH_BUFFER_NAME: &str = "[scratch]";
+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Mode {
Normal,
@@ -96,7 +98,7 @@ pub struct Document {
// It can be used as a cell where we will take it out to get some parts of the history and put
// it back as it separated from the edits. We could split out the parts manually but that will
// be more troublesome.
- history: Cell<History>,
+ pub history: Cell<History>,
pub savepoint: Option<Transaction>,
@@ -494,7 +496,9 @@ impl Document {
/// Detect the programming language based on the file type.
pub fn detect_language(&mut self, theme: Option<&Theme>, config_loader: &syntax::Loader) {
if let Some(path) = &self.path {
- let language_config = config_loader.language_config_for_file_name(path);
+ let language_config = config_loader
+ .language_config_for_file_name(path)
+ .or_else(|| config_loader.language_config_for_shebang(self.text()));
self.set_language(theme, language_config);
}
}
@@ -749,19 +753,35 @@ impl Document {
}
/// Undo modifications to the [`Document`] according to `uk`.
- pub fn earlier(&mut self, view_id: ViewId, uk: helix_core::history::UndoKind) {
+ pub fn earlier(&mut self, view_id: ViewId, uk: helix_core::history::UndoKind) -> bool {
let txns = self.history.get_mut().earlier(uk);
+ let mut success = false;
for txn in txns {
- self.apply_impl(&txn, view_id);
+ if self.apply_impl(&txn, view_id) {
+ success = true;
+ }
}
+ if success {
+ // reset changeset to fix len
+ self.changes = ChangeSet::new(self.text());
+ }
+ success
}
/// Redo modifications to the [`Document`] according to `uk`.
- pub fn later(&mut self, view_id: ViewId, uk: helix_core::history::UndoKind) {
+ pub fn later(&mut self, view_id: ViewId, uk: helix_core::history::UndoKind) -> bool {
let txns = self.history.get_mut().later(uk);
+ let mut success = false;
for txn in txns {
- self.apply_impl(&txn, view_id);
+ if self.apply_impl(&txn, view_id) {
+ success = true;
+ }
+ }
+ if success {
+ // reset changeset to fix len
+ self.changes = ChangeSet::new(self.text());
}
+ success
}
/// Commit pending changes to history