Skip to content
This repository was archived by the owner on Dec 16, 2021. It is now read-only.

Commit b1aeca4

Browse files
committed
Baremode now shows the editor as well
1 parent 7b08c0a commit b1aeca4

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

ui/editor.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ func NewEditor() *Editor {
436436
return nil
437437
} else if shortcuts.PasteAtSelection.Equals(event) {
438438
editor.Paste(event)
439-
editor.triggerHeightRequestIfNecessary()
439+
editor.TriggerHeightRequestIfNecessary()
440440
return nil
441441
} else if shortcuts.InputNewLine.Equals(event) {
442442
editor.InsertCharacter('\n')
@@ -448,7 +448,7 @@ func NewEditor() *Editor {
448448
return event
449449
}
450450

451-
editor.triggerHeightRequestIfNecessary()
451+
editor.TriggerHeightRequestIfNecessary()
452452
editor.internalTextView.ScrollToHighlight()
453453
return nil
454454
})
@@ -480,14 +480,24 @@ func (editor *Editor) countRows(text string) int {
480480
return tviewutil.CalculateNecessaryHeight(width, text)
481481
}
482482

483-
func (editor *Editor) triggerHeightRequestIfNecessary() {
483+
// TriggerHeightRequestIfNecessary informs the parent that more or less height
484+
// is requierd for rendering than currently in use, unless the height is already
485+
// optimal.
486+
func (editor *Editor) TriggerHeightRequestIfNecessary() {
484487
if editor.heightRequestHandler == nil {
485488
return
486489
}
487490

488491
rowAmount := editor.countRows(editor.GetText())
489492

490-
newRequestedHeight := rowAmount + 2 /*borders*/
493+
newRequestedHeight := rowAmount
494+
if editor.internalTextView.IsBorderTop() {
495+
newRequestedHeight++
496+
}
497+
if editor.internalTextView.IsBorderBottom() {
498+
newRequestedHeight++
499+
}
500+
491501
if newRequestedHeight != editor.requestedHeight {
492502
editor.requestedHeight = newRequestedHeight
493503
editor.heightRequestHandler(newRequestedHeight)
@@ -550,7 +560,7 @@ func (editor *Editor) SetText(text string) {
550560
editor.buffer.Cursor.ResetSelection()
551561
editor.buffer.Cursor.GotoLoc(editor.buffer.End())
552562
editor.applyBuffer()
553-
editor.triggerHeightRequestIfNecessary()
563+
editor.TriggerHeightRequestIfNecessary()
554564
}
555565

556566
// SetBorderFocusColor delegates to the underlying components

ui/window.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ func (window *Window) loadPrivateChannel(channel *discordgo.Channel) {
12861286
func (window *Window) insertNewLineAtCursor() {
12871287
window.messageInput.InsertCharacter('\n')
12881288
window.app.QueueUpdateDraw(func() {
1289-
window.messageInput.triggerHeightRequestIfNecessary()
1289+
window.messageInput.TriggerHeightRequestIfNecessary()
12901290
window.messageInput.internalTextView.ScrollToHighlight()
12911291
})
12921292
}
@@ -2229,6 +2229,18 @@ func (window *Window) handleGlobalShortcuts(event *tcell.EventKey) *tcell.EventK
22292229
return nil
22302230
}
22312231

2232+
//This two have to work in baremode as well, since otherwise only the mouse
2233+
//can be used for focus switching, which sucks in a terminal app.
2234+
if shortcuts.FocusMessageInput.Equals(event) {
2235+
window.app.SetFocus(window.messageInput.GetPrimitive())
2236+
return nil
2237+
}
2238+
2239+
if shortcuts.FocusMessageContainer.Equals(event) {
2240+
window.app.SetFocus(window.chatView.internalTextView)
2241+
return nil
2242+
}
2243+
22322244
if window.app.GetRoot() != window.rootContainer {
22332245
return event
22342246
}
@@ -2278,14 +2290,10 @@ func (window *Window) handleGlobalShortcuts(event *tcell.EventKey) *tcell.EventK
22782290
} else if shortcuts.FocusGuildContainer.Equals(event) {
22792291
window.SwitchToGuildsPage()
22802292
window.app.SetFocus(window.guildList)
2281-
} else if shortcuts.FocusMessageContainer.Equals(event) {
2282-
window.app.SetFocus(window.chatView.internalTextView)
22832293
} else if shortcuts.FocusUserContainer.Equals(event) {
22842294
if window.activeView == Guilds && window.userList.internalTreeView.IsVisible() {
22852295
window.app.SetFocus(window.userList.internalTreeView)
22862296
}
2287-
} else if shortcuts.FocusMessageInput.Equals(event) {
2288-
window.app.SetFocus(window.messageInput.GetPrimitive())
22892297
} else {
22902298
return event
22912299
}
@@ -2321,12 +2329,22 @@ func (window *Window) toggleUserContainer() {
23212329
func (window *Window) toggleBareChat() {
23222330
window.bareChat = !window.bareChat
23232331
if window.bareChat {
2324-
window.chatView.internalTextView.SetBorder(false)
2325-
window.app.SetRoot(window.chatView.GetPrimitive(), true)
2332+
window.chatView.internalTextView.SetBorderSides(true, false, true, false)
2333+
window.messageInput.internalTextView.SetBorderSides(false, true, false, true)
2334+
previousFocus := window.app.GetFocus()
2335+
window.app.SetRoot(window.chatArea, true)
2336+
window.app.SetFocus(previousFocus)
23262337
} else {
2327-
window.chatView.internalTextView.SetBorder(true)
2338+
window.chatView.internalTextView.SetBorderSides(true, true, true, true)
2339+
window.messageInput.internalTextView.SetBorderSides(true, true, true, true)
23282340
window.app.SetRoot(window.rootContainer, true)
2341+
window.app.SetFocus(window.messageInput.GetPrimitive())
23292342
}
2343+
2344+
window.app.QueueUpdateDraw(func() {
2345+
window.messageInput.TriggerHeightRequestIfNecessary()
2346+
window.chatView.Reprint()
2347+
})
23302348
}
23312349

23322350
// FindCommand searches through the registered command, whether any of them

0 commit comments

Comments
 (0)