From fb35e0312a3d2e9456b966e362fa2356931fc62b Mon Sep 17 00:00:00 2001 From: dmaluka Date: Fri, 15 May 2020 03:50:28 +0200 Subject: [PATCH 1/4] Fix unbind of a rune (#1649) Fix problem with non-working unbind of a rune key. E.g. after the following commands: bind "n" "FindNext" unbind "n" Observed result: "n" key still triggers FindNext action Expected result: "n" key inserts "n" rune --- internal/action/bindings.go | 1 + internal/action/bufpane.go | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/internal/action/bindings.go b/internal/action/bindings.go index 247202f3..fd57eb9c 100644 --- a/internal/action/bindings.go +++ b/internal/action/bindings.go @@ -249,6 +249,7 @@ func UnbindKey(k string) error { if a, ok := defaults[k]; ok { BindKey(k, a) } else if _, ok := config.Bindings[k]; ok { + BufUnmap(key) delete(config.Bindings, k) } diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index 0daf8afd..a422f4c2 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -139,6 +139,17 @@ func BufMapMouse(k MouseEvent, action string) { } } +// BufUnmap unmaps a key or mouse event from any action +func BufUnmap(k Event) { + delete(BufKeyBindings, k) + delete(BufKeyStrings, k) + + switch e := k.(type) { + case MouseEvent: + delete(BufMouseBindings, e) + } +} + // The BufPane connects the buffer and the window // It provides a cursor (or multiple) and defines a set of actions // that can be taken on the buffer From d0f7ecf9caf2e9516257478303619d6cfbe5135f Mon Sep 17 00:00:00 2001 From: Jeff Warner Date: Thu, 14 May 2020 18:51:49 -0700 Subject: [PATCH 2/4] =?UTF-8?q?Adds=20command=20"tabmove=20=C2=B1n",=20for?= =?UTF-8?q?=20better=20tab=20management=20(#1636)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Adds command "tabmove ±n", for better tab management * Added tabmove to help:commands * Replace uses of util.Min, util.Max with util.Clamp Browsing code and discovered `util.Clamp`, ideal for this section of my code * oops, missed an arg * Typo, again --- internal/action/command.go | 51 ++++++++++++++++++++++++++++++++++++++ runtime/help/commands.md | 5 ++++ 2 files changed, 56 insertions(+) diff --git a/internal/action/command.go b/internal/action/command.go index 1218bc42..8361e5a1 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -56,6 +56,7 @@ func InitCommands() { "cd": {(*BufPane).CdCmd, buffer.FileComplete}, "pwd": {(*BufPane).PwdCmd, nil}, "open": {(*BufPane).OpenCmd, buffer.FileComplete}, + "tabmove": {(*BufPane).TabMoveCmd, nil}, "tabswitch": {(*BufPane).TabSwitchCmd, nil}, "term": {(*BufPane).TermCmd, nil}, "memusage": {(*BufPane).MemUsageCmd, nil}, @@ -155,6 +156,56 @@ func (h *BufPane) TextFilterCmd(args []string) { h.Buf.Insert(h.Cursor.Loc, bout.String()) } +// TabMoveCmd moves the current tab to a given index (starts at 1). The +// displaced tabs are moved up. +func (h *BufPane) TabMoveCmd(args []string) { + if len(args) <= 0 { + InfoBar.Error("Not enough arguments: provide an index, starting at 1") + return + } + + if len(args[0]) <= 0 { + InfoBar.Error("Invalid argument: empty string") + return + } + + num, err := strconv.Atoi(args[0]) + if err != nil { + InfoBar.Error("Invalid argument: ", err) + return + } + + // Preserve sign for relative move, if one exists + var shiftDirection byte + if strings.Contains("-+", string([]byte{args[0][0]})) { + shiftDirection = args[0][0] + } + + // Relative positions -> absolute positions + idxFrom := Tabs.Active() + idxTo := 0 + offset := util.Abs(num) + if shiftDirection == '-' { + idxTo = idxFrom - offset + } else if shiftDirection == '+' { + idxTo = idxFrom + offset + } else { + idxTo = offset - 1 + } + + // Restrain position to within the valid range + idxTo = util.Clamp(idxTo, 0, len(Tabs.List)-1) + + activeTab := Tabs.List[idxFrom] + Tabs.RemoveTab(activeTab.ID()) + Tabs.List = append(Tabs.List, nil) + copy(Tabs.List[idxTo+1:], Tabs.List[idxTo:]) + Tabs.List[idxTo] = activeTab + Tabs.UpdateNames() + Tabs.SetActive(idxTo) + // InfoBar.Message(fmt.Sprintf("Moved tab from slot %d to %d", idxFrom+1, idxTo+1)) +} + // TabSwitchCmd switches to a given tab either by name or by number func (h *BufPane) TabSwitchCmd(args []string) { if len(args) > 0 { diff --git a/runtime/help/commands.md b/runtime/help/commands.md index ff4e9994..9f43085c 100644 --- a/runtime/help/commands.md +++ b/runtime/help/commands.md @@ -62,6 +62,11 @@ quotes here but these are not necessary when entering the command in micro. * `tab 'filename'`: opens the given file in a new tab. +* `tabmove '[-+]?n'`: Moves the active tab to another slot. `n` is an integer. + If `n` is prefixed with `-` or `+`, then it represents a relative position + (e.g. `tabmove +2` moves the tab to the right by `2`). If `n` has no prefix, + it represents an absolute position (e.g. `tabmove 2` moves the tab to slot `2`). + * `tabswitch 'tab'`: This command will switch to the specified tab. The `tab` can either be a tab number, or a name of a tab. From 299af4a3dbce5c81a85233ecadf5ea5d81acf588 Mon Sep 17 00:00:00 2001 From: jsyedidia Date: Sat, 16 May 2020 13:06:55 -0400 Subject: [PATCH 3/4] Update hlint to 3.0 syntax (#1659) --- runtime/plugins/linter/linter.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/plugins/linter/linter.lua b/runtime/plugins/linter/linter.lua index 469fbc98..b96ed15c 100644 --- a/runtime/plugins/linter/linter.lua +++ b/runtime/plugins/linter/linter.lua @@ -70,7 +70,7 @@ function init() makeLinter("dmd", "d", "dmd", {"-color=off", "-o-", "-w", "-wi", "-c", "%f"}, "%f%(%l%):.+: %m") makeLinter("gobuild", "go", "go", {"build", "-o", devnull, "%d"}, "%f:%l:%c:? %m") -- makeLinter("golint", "go", "golint", {"%f"}, "%f:%l:%c: %m") - makeLinter("hlint", "haskell", "hlint", {"%f"}, "%f:%l:%c: %m") + makeLinter("hlint", "haskell", "hlint", {"%f"}, "%f:%l:%c.-: %m") makeLinter("javac", "java", "javac", {"-d", "%d", "%f"}, "%f:%l: error: %m") makeLinter("jshint", "javascript", "jshint", {"%f"}, "%f: line %l,.+, %m") makeLinter("literate", "literate", "lit", {"-c", "%f"}, "%f:%l:%m", {}, false, true) From a150eef6f900b0bd23b19fbc59308bd267d66cdd Mon Sep 17 00:00:00 2001 From: dmaluka Date: Sun, 17 May 2020 22:05:34 +0200 Subject: [PATCH 4/4] Fix end line number in HighlightMatches (#1662) There is a bit of mess in the usage of HighlightMatches: in some places we assume that it updates lines from startline to endline inclusive, in other places we assume it's non-inclusive. This fix makes it always inclusive. In particular, it fixes a bug: when we open a file which has no newline at the end, the last line isn't highlighted. --- internal/buffer/buffer.go | 6 +++--- pkg/highlight/highlighter.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index 52fa262c..5525b1b7 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -152,14 +152,14 @@ func (b *SharedBuffer) MarkModified(start, end int) { return } - start = util.Clamp(start, 0, len(b.lines)) - end = util.Clamp(end, 0, len(b.lines)) + start = util.Clamp(start, 0, len(b.lines)-1) + end = util.Clamp(end, 0, len(b.lines)-1) l := -1 for i := start; i <= end; i++ { l = util.Max(b.Highlighter.ReHighlightStates(b, i), l) } - b.Highlighter.HighlightMatches(b, start, l+1) + b.Highlighter.HighlightMatches(b, start, l) } // DisableReload disables future reloads of this sharedbuffer diff --git a/pkg/highlight/highlighter.go b/pkg/highlight/highlighter.go index ae7c71b3..560c41a6 100644 --- a/pkg/highlight/highlighter.go +++ b/pkg/highlight/highlighter.go @@ -336,11 +336,11 @@ func (h *Highlighter) HighlightStates(input LineStates) { } } -// HighlightMatches sets the matches for each line in between startline and endline +// HighlightMatches sets the matches for each line from startline to endline // It sets all other matches in the buffer to nil to conserve memory // This assumes that all the states are set correctly func (h *Highlighter) HighlightMatches(input LineStates, startline, endline int) { - for i := startline; i < endline; i++ { + for i := startline; i <= endline; i++ { if i >= input.LinesNum() { break }