Skip to content

Commit

Permalink
Fixing issue with leading spaces on syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Shaw committed Jun 12, 2018
1 parent d9e8642 commit 31dca21
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,21 @@ func (h *Handler) outputHighlighter(s string) string {
endl += lineterm
}

// leading whitespace
var leading string

// capture current query statement buffer
orig := h.buf.RawString()
full := orig
if full != "" {
full += "\n"
} else {
// get leading whitespace
if i := strings.IndexFunc(s, func(r rune) bool {
return !stmt.IsSpace(r)
}); i != -1 {
leading = s[:i]
}
}
full += s

Expand Down Expand Up @@ -171,11 +181,12 @@ func (h *Handler) outputHighlighter(s string) string {
if !st.Ready() && cmd == "" {
final += st.RawString()
}
final = leading + final

// determine whatever is remaining after "active"
var remaining string
if len(final) < len(full) {
remaining = full[len(final):]
if finall := len(final); finall < len(full) {
remaining = full[finall:]
}

// this happens when a read line is empty and/or has only
Expand Down

0 comments on commit 31dca21

Please sign in to comment.