From 683d40a7ad09cb367dd8a73014360a95cec3cefb Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Thu, 19 Aug 2021 23:19:11 +0500 Subject: [PATCH 1/3] Migrate to Mycomarkup v1.0.3 Let's catch the new bugs --- go.mod | 4 ++-- go.sum | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 6791be4..e2a3163 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/bouncepaw/mycorrhiza go 1.16 require ( - github.com/bouncepaw/mycomarkup v1.0.1 + github.com/bouncepaw/mycomarkup v1.0.3 github.com/go-ini/ini v1.62.0 github.com/gorilla/feeds v1.1.1 github.com/gorilla/mux v1.8.0 @@ -17,4 +17,4 @@ require ( ) // Use this trick to test mycomarkup: -// replace github.com/bouncepaw/mycomarkup v1.0.1 => "/Users/bouncepaw/GolandProjects/mycomarkup" +// replace github.com/bouncepaw/mycomarkup v1.0.3 => "/Users/bouncepaw/GolandProjects/mycomarkup" diff --git a/go.sum b/go.sum index 1e5e8f4..19ae145 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= -github.com/bouncepaw/mycomarkup v1.0.1 h1:6GEpc49KtoCoP9XMn4hLq4FJrGK8r2NJ3yXHmS0qTRs= -github.com/bouncepaw/mycomarkup v1.0.1/go.mod h1:0n6thlGGgrx2Y/2NaaUH4qHW4v1xJ+EpW7yMFUxNRIg= +github.com/bouncepaw/mycomarkup v1.0.3 h1:FrL7VxS9wZDE+E0ROimf/fDgqUSvMJ2CIX1eKTdmAPQ= +github.com/bouncepaw/mycomarkup v1.0.3/go.mod h1:0n6thlGGgrx2Y/2NaaUH4qHW4v1xJ+EpW7yMFUxNRIg= github.com/go-ini/ini v1.62.0 h1:7VJT/ZXjzqSrvtraFp4ONq80hTcRQth1c9ZnQ3uNQvU= github.com/go-ini/ini v1.62.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= From 6a4df5aefd1ddf9c0ec4fd726830597200de301f Mon Sep 17 00:00:00 2001 From: Mikhail Chekan Date: Fri, 20 Aug 2021 16:45:38 +0800 Subject: [PATCH 2/3] Sort search results (subpath aware) --- shroom/search.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/shroom/search.go b/shroom/search.go index e9ee449..bdce218 100644 --- a/shroom/search.go +++ b/shroom/search.go @@ -1,6 +1,7 @@ package shroom import ( + "sort" "strings" "github.com/bouncepaw/mycorrhiza/hyphae" @@ -11,11 +12,33 @@ func YieldHyphaNamesContainingString(query string) <-chan string { query = util.CanonicalName(query) out := make(chan string) go func() { + // To make it unicode-friendly and lean, we cast every string into rune slices, sort, and only then cast them back + raw := make([][]rune, 0) for h := range hyphae.YieldExistingHyphae() { if hyphaNameMatchesString(h.Name, query) { - out <- h.Name + raw = append(raw, []rune(h.Name)) } } + sort.Slice(raw, func(i, j int) bool { + const slash rune = 47 // == '/' + // Classic lexicographical sort with a twist + c := 0 + for { + if c == len(raw[i]) { return true } + if c == len(raw[j]) { return false } + if raw[i][c] == raw[j][c] { + c++ + } else { + // The twist: subhyphae-awareness is about pushing slash upwards + if raw[i][c] == slash { return true } + if raw[j][c] == slash { return false } + return raw[i][c] < raw[j][c] + } + } + }) + for _, name := range raw { + out <- string(name) + } close(out) }() return out From ba6a444063482a8e69ff005807382e5da19067f5 Mon Sep 17 00:00:00 2001 From: Mikhail Chekan Date: Sun, 22 Aug 2021 12:50:17 +0800 Subject: [PATCH 3/3] Make text decorations toggleable, like Github's --- static/toolbar.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/static/toolbar.js b/static/toolbar.js index e8c46f3..c2e27f8 100644 --- a/static/toolbar.js +++ b/static/toolbar.js @@ -5,6 +5,11 @@ function placeCursor(position, el = editTextarea) { el.selectionStart = el.selectionEnd } +function selectRange(left, right, el = editTextarea) { + el.selectionEnd = right + el.selectionStart = left +} + function getSelectedText(el = editTextarea) { const [start, end] = [el.selectionStart, el.selectionEnd] const text = el.value @@ -26,15 +31,35 @@ function textInserter(text, cursorPosition = null, el = editTextarea) { function selectionWrapper(cursorPosition, prefix, postfix = null, el = editTextarea) { return function() { - const [start, end] = [el.selectionStart, el.selectionEnd] + let [start, end] = [el.selectionStart, el.selectionEnd] if (postfix == null) { postfix = prefix } let text = getSelectedText(el) - let result = prefix + text + postfix + let removing = false + let result + if (text.startsWith(prefix) && text.endsWith(postfix)) { + // selection is decorated, so we just cut it + removing = true + result = text.substring(cursorPosition, text.length - cursorPosition) + } else if ( (prefix == el.value.slice(start-cursorPosition, start)) && + (postfix == el.value.slice(end, end+cursorPosition)) ) { + // selection is surrounded by decorations + removing = true + result = text + start -= cursorPosition + end += cursorPosition + } else { + // no decorations, so we add them + result = prefix + text + postfix + } el.setRangeText(result, start, end, 'select') el.focus() - placeCursor(end + cursorPosition) + if (removing) { + selectRange(start, end-cursorPosition*2) + } else { + selectRange(start+cursorPosition, end+cursorPosition) + } } }