Comments (6)
At the moment, I am considering possible solutions to the Colour Panic bug, see #42, and came across the strip_trailing_whitespace()
function, as well.
I found this implementation working identically compared to the current one:
pub fn strip_trailing_whitespace(text: Rope) -> Rope {
text.lines()
.map(|x| x.to_string().trim_end().to_string() + "\n")
.collect()
}
Does this version raise the performance when changing the implementation in zee-edit/src/graphemes.rs
, line 122, or is it even worse? Maybe the performance boost suffices to save the file before the exit?
from zee.
Despite that my suggestion adds another newline to end of the buffer, how does it perform in contrast to the original implementation regarding your example on your machine?
from zee.
In my opinion, there are two major starting points to solve this issue:
- Implement a mechanism to wait for the saving to finish before leaving the application.
- Optimise the whitespace cropping.
Implementing just one of them leaves the other one open and, thus, makes it source for further bugs. The complete solution should consist of an implementation of both features.
Regarding the waiting mechanism, we would need to signal the end of the saving operation to the key input handler. The first question to answer is how the writing operation's ending can be queried without interrupting it. Freezing the editor as long as the file is written is surely not the most preferable option but in the end, it would be an emergency solution.
When taking a look at the implementation of the whitespace cropping function, it looks for me as if the an implementation using iterators would be more efficient since at the moment, the required values are queried whenever they are needed which seems to cause this implementation taking much time. The iterator approach would just go over the whole text once without needing to lookup neighboured data multiple times since it is implicit. Unfortunately, the collectors are not very flexible which may cause unnecessary type conversions.
Any ideas?
from zee.
I've opened PR #60 to add a configuration parameter to disable removing trailing white space on save. My thought process on this is that it is expensive and might not be the right for all users in all cases. As mentioned in the PR, my changes also move the call to remove trailing white space from between when the file is truncated and when it is written to before it is truncated which doesn't fix the issue with the user being able to close the application while the file is still being written but it should greatly reduce the chances of triggering it in most cases.
In addition, I agree with the need to implement both a mechanism to wait for saving to finish and to optimize the white space trimming code. I did so prototyping on disallowing exiting while a file is being saved (why "dirty buffers exist really) and it looks fairly straight forward. Buffers track their modify status so anything that isn't ModifiedStatus::Unchanged
can be considered "dirty". Not what we'd want to commit but here's a PoC:
diff --git a/zee/src/editor/mod.rs b/zee/src/editor/mod.rs
index 4075477..73e9aa4 100644
--- a/zee/src/editor/mod.rs
+++ b/zee/src/editor/mod.rs
@@ -374,7 +374,17 @@ impl Component for Editor {
self.prompt_height = self.prompt_action.initial_height();
}
Message::Quit => {
- self.context.link.exit();
+ if !self
+ .buffers
+ .iter()
+ .any(|buffer| buffer.modified_status() != ModifiedStatus::Unchanged)
+ {
+ self.context.link.exit();
+ } else {
+ self.context.link.send(Message::Log(Some(
+ "Unable to quit. Unsaved buffers exist".to_string(),
+ )));
+ }
}
Message::Buffer(message) => self.buffers.handle_message(message),
_ => {}
To do this properly, I think we would need a new variant of PromptAction which displays a message such as "Unsaved buffer exist, quit anyway? yes/no" and allows the user to enter yes/no or y/n. The user's input would then control whether the original request to quit is completed utilizing the callback mechanism.
Optimizing strip_trailing_whitespace()
is itself an interesting problem to solve. I'll write a standalone application that performs only that operation to get some concrete performance numbers and I'll try your implementation, see how it compares.
from zee.
How about making the waiting for the saving to finish an option for the configuration file, as well?
from zee.
@kevinmatthes the big issue with the above PoC and why I mention that it shouldn't be committed it is that it stops the user from being able to exit without saving even in cases where they don't want to persist the changes made, for example when using zee to temporarily write something up that will be copied to another application. I think adding a option to the configuration for this would be short lived since it would go away if/when interactive messages are added to zee.
from zee.
Related Issues (20)
- [Enhancement] Modular Structure of Theme Definition
- [Enhancement] Installation Instructions for Nightly Build
- [Bug] Copy and Paste without System Clipboard not Working HOT 4
- [Project Idea] Introduce Github discussions, gitter, or similar? HOT 3
- [Feature Request] Shortcut for Reloading Buffers HOT 5
- [Feature Request] Set Exit Codes when Quitting the Application HOT 3
- Performance of `strip_trailing_whitespace()` HOT 8
- [Bug] Visual Width of Tab Characters in Edge Cases HOT 2
- [Feature Request] Add Intendation Information to Status Bar
- [Bug] Vanishing Separators in the Status Bar HOT 9
- [Bug] No Upward Cursor Movement with CRLF Ended Lines Possible HOT 1
- [Question] Behaviour Regarding Multiple Suffixes HOT 1
- [Question] Highlighting Scheme Specification
- [Bug] Colour Mapping of `Base16Theme` Differs from Default Theme
- [Feature Request] Next Release
- [Bug] Unable to install zee with the system-clipboard feature enabled
- [Feature Request?] Incremental search
- Segmentation fault
- Error while installing with cargo HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zee.