Comments (8)
Hi
I noted this problem a while back (#2756), but could not make it reproducible.
At that time I assumed it was due to my inferior OS!
We should be careful not to confuse reopen
and reload
these are different commands:
reopen
: undocumented command to reopen current buffer using bp.Buf:ReOpen() functionreload
: this command reloads all runtime files (bindings.json, settings.json, init.lua, ?plugins?)
Confusingly, settings.json includes an option named reload
:
- "controls the reload behavior of the current buffer in case the file has changed. The available options are
prompt
,auto
&disabled
" which calls bp.Buf:ReOpen() !
I would be interested in a fix, so my spellchecking function (#2744) correctly reloads altered files.
Kind Regards Gavin Holt
from micro.
FWIW I can easily reproduce it, with the newest micro from master.
- open a file with DOS line endings (
\r\n
) - open the same file in another editor (or even in another instance of micro), add any text somewhere in the middle of the file, and save it
- reload the file (i.e. answer "yes" to the reload prompt) in the original instance of micro => result: the new text is inserted in the wrong place.
It's clearly a bug, and hopefully easy to fix (just need to find free time to do that).
We should be careful not to confuse
reopen
andreload
these are different commands:
Yeah, they are doing completely different things.
reopen
: undocumented command to reopen current buffer using bp.Buf:ReOpen() function
Indeed, and it might be a good moment to document it.
reload
: this command reloads all runtime files (bindings.json, settings.json, init.lua, ?plugins?)
Yep, it reloads plugins too.
We are considering improving its documentation: #3240 (review)
Confusingly, settings.json includes an option named
reload
:
- "controls the reload behavior of the current buffer in case the file has changed. The available options are
prompt
,auto
&disabled
" which calls bp.Buf:ReOpen() !
The reopen
command does the same thing that is done automatically if the reload
option is set to prompt
or auto
, i.e. reloads the file. So it's not surprising that ReOpen()
is called in both cases.
Yeah, it might be confusing that the reload
command (not option) does a completely different thing.
from micro.
Thanks for the pointer to reopen
. So it looks like the error occurs in EventHandler.ApplyDiff. Here's a fragment of the diff operations performed
State of LineArray
"569"
"489"
"45"
Diff to Process
{"Equal" "9\r\n"} @ {X:2 Y:0}
State of LineArray
"569"
"489"
"45"
Diff to Process
{"Delete" "48"} @ {X:1 Y:1} <- NOTE: should be {X:0 Y:1}
State of LineArray
"569"
"4" <- NOTE: 89 deleted instead of 48
"45"
So the error seems to be that when \r\n
is encountered, the location advances two positions to the right, instead of only one. This misaligns the locations for all subsequent diff operations, which produces the garbled text.
from micro.
So the error seems to be that when
\r\n
is encountered, the location advances two positions to the right, instead of only one.
Thank you for the great hint!
micro/internal/util/unicode.go
Line 90 in 35630aa
->
if r != '\r' && !isMark(r) {
Most probably there is a more elegant and especially generic way, since this was just shot out of my hip. 😉
@scurest:
Does the proposal work for you too?
from micro.
ApplyDiff
is also wrong in the presence of marks.
echo -e 'Te\u0302st' > test.txt # COMBINING CIRCUMFLEX ACCENT
# Open in micro, shows 'Têst'
echo -e 'Test' > test.txt
# Reload in micro, still shows 'Têst'
from micro.
Hi,
ApplyDiff
sounds complicated, and not strictly necessary for reopen
.
Could reopen
just read the whole disc copy and reposition the cursor to the last known editing location?
Kind Regards Gavin Holt
PS. I would also expect reopen
to clear the undo stack.
from micro.
ApplyDiff
maintains the "logical" cursor position.
echo 'The bottle says DRINK ME' > test.txt
# Open in micro, 'The bottle says DRINK |ME' (| denotes cursor location)
echo 'The cake says EAT ME' > test.txt
# Reload in micro, 'The cake says EAT |ME' (cursor maintained at ME)
Is this the only reason it's used? I would also be fine giving this up for correct reopen
.
Also the line-ending mode is not re-detected when reopen
ing.
from micro.
Is this the only reason it's used?
No. The main purpose is to handle every insertion and/or deletion independent to track it inside the undo buffer. Furthermore the modifications can be visualized with the diffgutter
.
The cursor position is handled here:
micro/internal/buffer/buffer.go
Line 560 in e9bd1b3
So bypassing or removing ApplyDiff
is no option so far. It just need to work correctly in these scenarios.
Currently you broke it down to some minimal reproduction cases, which is good so far.
Just image the use case where you've a much larger file which is edited outside of you current buffer...maybe you would like to see the diff and maybe you'd like to undo something.
from micro.
Related Issues (20)
- palettero plugin breaks `\u001b[` keybindings
- lock to provide warning when opening a file already opened in another instance of micro HOT 2
- set filetype sets the filetype for all opened tabs and not the current focused HOT 4
- Feature proposal: TUI drop-down menus HOT 2
- Enhanced multi-line editing
- Why doesn't Micro use Nano's syntax coloring? HOT 6
- [WSL] Font changed to Raster Fonts when opening Micro
- Changing default linter behaviour HOT 1
- how to input nano keybinds into micro? HOT 5
- Maybe redo should keep cursor where modification happens (not respecting pure line change in redoing)? HOT 6
- Micro places compiled Java programs into incorrect directory when auto-compiling HOT 2
- Running remote commands causes the editor to freeze up HOT 2
- Scroll with moving the scrollbar - a small idea for more convenience HOT 2
- Request (or just a general question) about .mo (modelica) syntax highlight support. HOT 1
- Weird tab bar behavior HOT 1
- Jumping to matching brace not as expected HOT 8
- editorconfig not applied HOT 2
- XHTML? HOT 3
- Distribution with DotSlash? HOT 1
- Match brace highlight is not working at all. HOT 4
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 micro.