Commit graph

705 commits

Author SHA1 Message Date
Neko Box Coder 3b3fe63f19
Exposing replacement functions for deprecated IOUtil functions (#3393) 2024-09-22 22:08:32 +02:00
Massimo Mund 4f4a13a9a1
Implemented SkipMultiCursorBack as a counterpart to SkipMultiCursor (#3404) 2024-09-16 22:20:12 +02:00
Dmytro Maluka 9eaeb193d4
Merge pull request #3403 from masmu/refactor/tab-actions
Implemented new actions `FirstTab`, `LastTab`, `FirstSplit` and `LastSplit`
2024-09-16 22:19:36 +02:00
Dmytro Maluka ca6012086b
Merge pull request #3335 from dmaluka/line-actions-cleanup
Improve and unify `CopyLine`, `CutLine`, `DeleteLine`, `DuplicateLine` actions
2024-09-16 22:19:05 +02:00
Massimo Mund 5f83661fee Fixes a bug where new BufPanes are not being inserted into the right array index.
When adding a new `BufPane` it is always being inserted last into `MainTab().Panes`.
This leads to a confusion when using the actions `PreviousSplit`, `NextSplit` as the previous/next split may not be the expected one.

How to reproduce:
- Launch micro and insert char "1"
- Open a new vsplit via the command `vsplit` and insert "2"
- Switch back to the left split (1) by using `PreviousSplit`
- Again open a new vsplit via command: `vsplit` and type char "3"
- Now switch between the 3 splits using `PreviousSplit`, `NextSplit`

Switching from most left split to the most right, the expected order would be 1, 3, 2 but actually is 1, 2, 3.
2024-09-15 16:36:00 +02:00
Massimo Mund 2e44db1ee9 Implemented new actions FirstTab, LastTab, FirstSplit and LastSplit and changed the default behavior of NextTab, PreviousTab, NextSplit, PreviousSplit to not walk in circles anymore 2024-09-15 16:35:22 +02:00
Dmytro Maluka d6d0b26041
Fix non-working raw escape bindings after restarting the screen (#3468)
When we temporarily disable the screen (e.g. during RunInteractiveShell)
and then enable it again, we reinitialize tcell.Screen from scratch, so
we need to register all previously registered raw escape sequences once
again. Otherwise raw escape bindings stop working, since the list of
raw escape sequences of this newly create tcell.Screen is empty.

Fixes #3392
2024-09-12 20:39:14 +02:00
Neko Box Coder e6b20b2ce9
Adding SpawnCursorAtLoc for plugin to use (#3441) 2024-08-31 12:42:55 +02:00
Jöran Karl b80ea93486 config: Correct typo in validatePositiveValue() 2024-08-18 22:28:51 +02:00
Jöran Karl 33b7c9db7c config: Don't truncate float64 to int 2024-08-18 22:28:51 +02:00
Jöran Karl 8b31dc79bf config: Rework autosave to be rearmed upon change 2024-08-18 22:28:49 +02:00
Jöran Karl 4170df89eb config: Use float64 within the autosave processing 2024-08-18 21:10:37 +02:00
Jöran Karl 832c7deaf8 config: Remove unused GetAutoTime() 2024-08-18 21:10:37 +02:00
Jöran Karl 0542765d95 action/command: Simplify ResetCmd
It doesn't need to loop over the DefaultCommonSettings() again,
since they're already included in the default settings and set via
SetGlobalOptionNative().
2024-08-18 21:10:37 +02:00
Jöran Karl 10511c9baf buffer/buffer: Store fileformat in LocalSettings on auto detection 2024-08-18 21:10:37 +02:00
Jöran Karl a3071b173b action/command: Refactor reload & the filetype change 2024-08-18 21:10:37 +02:00
Jöran Karl 724e29446f action/command: On reload prevent overwriting local settings 2024-08-18 21:10:37 +02:00
Jöran Karl 05529596cf action/command: Prevent overwriting settings set locally or by plugin
- on `reload`
- on `filetype` change
2024-08-18 21:10:37 +02:00
Jöran Karl f661b64e0a config/settings: Remove duplicating DefaultGlobalSettings()
Additionally pricise the documentation of the remaining
DefaultCommonSettings() and DefaultAllSettings() functions.
2024-08-18 21:10:37 +02:00
Jöran Karl 4663927098 config: Refactor parsed option handling
Validate the parsed options directly after read and inform about errors.
2024-08-18 21:10:37 +02:00
Jöran Karl 395d848980 buffer/settings: Prevent setting of unchanged option 2024-08-18 21:10:37 +02:00
Jöran Karl c741e36d2d action/command: Prevent setting of unchanged option 2024-08-18 21:10:37 +02:00
Jöran Karl 521b63a28c buffer/settings: On filetype change reload parsed local settings only
Additionally keep volatile settings as they have been set by the user.
2024-08-18 21:10:37 +02:00
Jöran Karl 62c1c667b8 buffer/settings: On filetype change remove the following steps
- reload runtime files
- reset globals
- parse the settings again

since this isn't the task of a filetype change.
2024-08-18 21:10:37 +02:00
Jöran Karl c67a30e611 action/command: On reload prevent overwriting volatile settings 2024-08-18 21:10:37 +02:00
Jöran Karl c51f848df2 action/command: On reload prevent overwriting settings.json 2024-08-18 21:10:37 +02:00
Jöran Karl 7f6e5bc860 action/command: On reload check and inform about errors 2024-08-18 21:10:37 +02:00
Jöran Karl 9afcb80c95 action/command: Let reload really reload the settings.json 2024-08-18 21:10:37 +02:00
Dmytro Maluka fd3a00226c
Add matchbraceleft option (#3432)
Add `matchbraceleft` option to allow disabling the default behavior
matching not just the brace under cursor but also the brace to the left
of it (which is arguably convenient, but also ambiguous and
non-intuitive). With `matchbraceleft` disabled, micro will only match
the brace character that is precisely under the cursor, and also when
jumping to the matching brace, will always move cursor precisely to the
matching brace character, not to the character next to it.

Nota bene: historical journey:

- There was already a `matchbraceleft` option introduced in commit
  ea6a87d41a, when this feature (matching brace to the left) was
  introduced first time. That time it was matching _only_ the brace
  to the left, _instead_ of the brace under the cursor, and was
  disabled by default.

- Later this feature was removed during the big refactoring of micro.

- Then this feature was reintroduced again in commit d1e713ce08, in
  its present form (i.e. combined brace matching both under the cursor
  and to the left, simulating I-beam cursor behavior), and it was
  introduced unconditionally, without an option to disable it.

- Since then, multiple users complained about this feature and asked
  for an option to disable it, so now we are reintroducing it as an
  option again (this time enabled by default though).
2024-08-18 21:08:05 +02:00
Dmytro Maluka 0b15b57e63 buffer: Set fastdirty=true for large file when reopening
Similarly to how we force `fastdirty` to true when opening a large file
(when creating the buffer), force it also when reopening a file, in case
the file on disk became large since we opened it.
2024-08-18 15:51:47 +02:00
Dmytro Maluka d31095fe8f buffer/settings: Add comment why do we need to zero origHash 2024-08-18 15:51:47 +02:00
Dmytro Maluka 7fe98ccfee calcHash: Remove checking file size
Let calcHash() unconditionally hash whatever buffer it is asked to hash,
and let its callers explicitly check if the buffer is too large before
calling calcHash(). This makes things simpler and less error-prone
(no extra source of truth about whether the file is too large, we don't
need to remember to check if calcHash() fails, we can be sure calcHash()
will actually update the provided hash), and actually faster (since just
calculating the buffer size, i.e. adding line lengths, is faster than
md5 calculation).

In particular, this fixes the following bugs:

1. Since ReOpen() doesn't check calcHash() return value, if the reloaded
   file is too large while the old version of the file is not,
   calcHash() returns ErrFileTooLarge and doesn't update origHash, so
   so Modified() returns true since the reloaded file's md5 sum doesn't
   match the old origHash, so micro wrongly reports the newly reloaded
   file as modified.

2. Since Modified() doesn't check calcHash() return value, Modified()
   may return false positives or false negatives if the buffer has
   *just* become too large so calcHash() returns ErrFileTooLarge and
   doesn't update `buff`.
2024-08-18 15:42:18 +02:00
Dmytro Maluka 93efc9eabe buffer/settings: Don't use Modified() before we updated origHash
When we have already enabled `fastdirty` but have not updated origHash
yet, we shouldn't use Modified() since it depends on origHash which is
still outdated, and thus returns wrong values.

This fixes the following issue: enable `fastdirty`, modify the buffer,
save the buffer and disable `fastdirty` -> micro wrongly reports the
buffer as modified (whereas it has just been saved).

Note that this fix, though, also causes a regression: e.g. if we run
`set fastdirty false` while fastdirty is already disabled, micro may
unexpectedly report a non-modified buffer as modified (in the case if
isModified is true but the buffer it actually not modified, since its
md5 sum matches and fastdirty is disabled), since this fix assumes that
since we are disabling fastdirty, it has been enabled. This shall be
fixed by PR #3343 which makes `set` do nothing if the option value
doesn't change.
2024-08-18 15:39:47 +02:00
Jöran Karl 352fd2be22 buffer/settings: On fastdirty off set to on in case of "large file"
This behavior is then aligned to the actual documentation of `fastdirty`.
Additionally set the origHash to zero in case the buffer was already modified.
2024-08-18 14:01:35 +02:00
Dmytro Maluka c0f6b65ed6 calcHash: use correct line endings
Make calcHash() respect the buffer's file endings (unix vs dos), to make
its calculation of the file size consistent with how we calculate it in
other cases (i.e. when opening or saving the file) and with the
`fastdirty` option documentation, i.e. make calcHash() return
ErrFileTooLarge if and only if the exact file size exceeds 50KB.
2024-08-18 13:35:37 +02:00
Dmytro Maluka e0f5361d97 calcHash: remove unneeded h.Write() error checks
According to the Go hash package documentation [1]:

type Hash interface {
	// Write (via the embedded io.Writer interface) adds more data to the running hash.
	// It never returns an error.
	io.Writer

[1] https://pkg.go.dev/hash#Hash
2024-08-18 13:35:27 +02:00
Dmytro Maluka 3737979139
Merge pull request #3416 from dmaluka/undo-cursor-fix
Fix cursor moving to an unexpected location after a redo
2024-08-15 16:07:51 +02:00
Neko Box Coder be69b2580b
Adding missing deselect when calling RemoveAllMultiCursors (#3428)
This adds missing deselect calls that were present previously for
RemoveAllMultiCursors before PR #3352
2024-08-15 16:06:32 +02:00
Dmytro Maluka 0d51035acd undo/redo: Remove no longer needed teCursor temp var 2024-08-04 13:56:03 +02:00
Dmytro Maluka 658c20ff2a undo/redo: Don't change remembered cursor location
Remember the cursor location in TextEvent just once - when the original
text event happens, so that when we redo after an undo, the cursor is
placed at the location where the actual redone modification happens (as
the user would expect), not at the location where the cursor was before
the undo (which may be a completely unrelated location and may be far
away).

Fixes #3411
2024-08-04 13:43:16 +02:00
Justin Su 2259fd10af
Add Shift-Page Up/Down keybindings (#3407)
* Add Shift-Page Up/Down keybindings in defaults_other.go

* Add Shift-Page Up/Down keybindings in defaults_darwin.go

* Document Shift-Page Up/Down keybindings in keybindings.md

* Fix indentation
2024-07-31 20:35:09 +02:00
Dmytro Maluka d173e527ac
Merge pull request #3352 from dmaluka/action-return-values
Some checks are pending
Build and Test / test (1.19.x, windows-latest) (push) Waiting to run
Build and Test / test (1.19.x, ubuntu-latest) (push) Waiting to run
Build and Test / test (1.19.x, macos-latest) (push) Waiting to run
Improve return values of some actions + some improvements
2024-07-20 15:52:18 +02:00
hchac f8e532b0d7
Adding selection for ParagraphPrevious and ParagraphNext. (#3353)
Also tweaked the behavior of Paragraph/{Previous/Next} so that it skips
all empty lines immediately next to cursor position, until it finds the
start/end of the paragraph closest to it. Once it finds the paragraph
closest to it, the same behavior as before applies. With the previous
behavior if the cursor was surrounded by empty lines, then
Paragraph/{Previous/Next} would only jump to the next empty line,
instead of jumping to the start/end of a paragraph.
2024-07-20 12:21:57 +02:00
Dmytro Maluka 0373a63b31 Refactor action execution code
Instead of calling execAction() and then letting it check whether it
should actually execute this action, do this check before calling
execAction(), to make the code clear and straightforward.

Precisely: for multicursor actions, call execAction() in a loop for
every cursor, but for non-multicursor actions, call execAction() just
once, without a loop. This, in particular, allows to get rid of the
hacky "c == nil" check, since we no longer iterate a slice that may
change in the meantime (since SpawnMultiCursor and RemoveMultiCursor
are non-multicursor actions and thus are no longer executed while
iterating the slice).
2024-07-18 23:54:57 +02:00
Dmytro Maluka 765889f610 Fix execution of {Spawn,Remove}MultiCursor in chained actions
- SpawnMultiCursor and RemoveMultiCursor actions change the set of
  cursors, so we cannot assume that it stays the same. So refresh the
  `cursors` list after executing every action in the chain.

- If execAction() did not execute an action since it is not a
  multicursor, it should return true, not false, to not prevent
  executing next actions in the chain.
2024-07-18 23:54:57 +02:00
Dmytro Maluka 5c8bf6b3a6 Improve RemoveAllMultiCursors behavior
Use Deselect() in order to place the cursor at the beginning of the
selection, not at the end of it, and to refresh its LastVisualX.
2024-07-18 23:54:57 +02:00
Dmytro Maluka aa9c476b1e Improve RemoveMultiCursor behavior
If the original selection was not done by the user manually but as a
result of the initial SpawnMultiCursor, deselect this original selection
if we execute RemoveMultiCursor and there is no multicursor to remove
(i.e. the original spawned cursor is the only one). This improves user
experience by making RemoveMultiCursor behavior nicely symmetrical to
SpawnMultiCursor.
2024-07-18 23:54:57 +02:00
Dmytro Maluka 2793c37a94 Fix SkipMultiCursor behavior when there is no selection
When there is no selection (i.e. selection is empty), SkipMultiCursor
searches for the empty text, "finds" it as the beginning of the buffer,
and as a result, jumps to the beginning of the buffer, which confuses
the user. Fix it.
2024-07-18 23:54:57 +02:00
Dmytro Maluka 7e09a921e4 Make it clear that ClearStatus is the same as ClearInfo
ClearInfo and ClearStatus actions do exactly the same thing. Let's keep
them both, for compatibility reasons (who knows how many users are using
either of the two), but at least document that there is no difference
between the two.
2024-07-18 23:54:56 +02:00
Dmytro Maluka e2e8baf4f3 Improve misc actions return values 2024-07-18 23:54:14 +02:00