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

Commit

Permalink
Updated / Added some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Bios-Marcel committed Sep 12, 2020
1 parent c84561e commit c66351b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ui/chatview.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ import (
)

const dashCharacter = "\u2500"
const EMBED_TIMESTAMP_FORMAT = "2006-01-02 15:04"

// embedTimestampFormat represents the format for times used when
// rendering embeds.
const embedTimestampFormat = "2006-01-02 15:04"

var (
successiveCustomEmojiRegex = regexp.MustCompile("<a?:.+?:\\d+(><)a?:.+?:\\d+>")
Expand Down Expand Up @@ -787,7 +790,7 @@ func (chatView *ChatView) formatDefaultMessageText(message *discordgo.Message) s
embedBuffer.WriteString(" - ")
}
localTime := parsedTimestamp.Local()
embedBuffer.WriteString(localTime.Format(EMBED_TIMESTAMP_FORMAT))
embedBuffer.WriteString(localTime.Format(embedTimestampFormat))
} else {
log.Println("Error parsing time: " + err.Error())
}
Expand Down
22 changes: 22 additions & 0 deletions ui/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func (editor *Editor) checkForAutocompletion() {
}
}

// MoveCursorLeft moves the cursor left by one cell.
func (editor *Editor) MoveCursorLeft() {
if editor.buffer.Cursor.HasSelection() {
editor.buffer.Cursor.GotoLoc(editor.buffer.Cursor.CurSelection[0])
Expand All @@ -120,6 +121,7 @@ func (editor *Editor) MoveCursorLeft() {
editor.applyBuffer()
}

// MoveCursorRight moves the cursor right by one cell.
func (editor *Editor) MoveCursorRight() {
if editor.buffer.Cursor.HasSelection() {
editor.buffer.Cursor.GotoLoc(editor.buffer.Cursor.CurSelection[1])
Expand All @@ -131,10 +133,14 @@ func (editor *Editor) MoveCursorRight() {
editor.applyBuffer()
}

// SelectionToLeft extends the selection one cell to the left.
func (editor *Editor) SelectionToLeft() {
editor.selectLeft(false)
}

// SelectWordLeft extends the selection one word to the left. A word may
// span multiple words. A word however can be one cell and mustn't be a word
// in terms of human language definition.
func (editor *Editor) SelectWordLeft() {
editor.selectLeft(true)
}
Expand Down Expand Up @@ -169,10 +175,14 @@ func (editor *Editor) selectLeft(word bool) {
editor.applyBuffer()
}

// SelectionToRight extends the selection one cell to the right.
func (editor *Editor) SelectionToRight() {
editor.selectRight(false)
}

// SelectWordRight extends the selection one word to the right. A word may
// span multiple words. A word however can be one cell and mustn't be a word
// in terms of human language definition.
func (editor *Editor) SelectWordRight() {
editor.selectRight(true)
}
Expand Down Expand Up @@ -202,6 +212,8 @@ func (editor *Editor) selectRight(word bool) {
editor.applyBuffer()
}

// SelectAll selects all text (cells) currently filled. If no text is
// available, nothing will change.
func (editor *Editor) SelectAll() {
start := editor.buffer.Start()
editor.buffer.Cursor.SetSelectionStart(start)
Expand All @@ -211,6 +223,9 @@ func (editor *Editor) SelectAll() {
editor.applyBuffer()
}

// SelectToStartOfLine will select all text to the left til the next newline
// is found. Lines doesn't mean "editor line" in this context, as the editor
// doesn't currently support vertical navigation.
func (editor *Editor) SelectToStartOfLine() {
oldCursor := editor.buffer.Cursor.Loc
editor.buffer.Cursor.StartOfText()
Expand All @@ -224,6 +239,9 @@ func (editor *Editor) SelectToStartOfLine() {
editor.applyBuffer()
}

// SelectToEndOfLine will select all text to the right til the next newline
// is found. Lines doesn't mean "editor line" in this context, as the editor
// doesn't currently support vertical navigation.
func (editor *Editor) SelectToEndOfLine() {
oldCursor := editor.buffer.Cursor.Loc
editor.buffer.Cursor.End()
Expand All @@ -232,6 +250,8 @@ func (editor *Editor) SelectToEndOfLine() {
editor.applyBuffer()
}

// SelectToStartOfText will select all text to the start of the editor.
// Meaning the top-left most cell.
func (editor *Editor) SelectToStartOfText() {
oldCursor := editor.buffer.Cursor.Loc
textStart := editor.buffer.Start()
Expand All @@ -241,6 +261,8 @@ func (editor *Editor) SelectToStartOfText() {
editor.applyBuffer()
}

// SelectToEndOfText will select all text to the end of the editor.
// Meaning the bottom-right most cell.
func (editor *Editor) SelectToEndOfText() {
oldCursor := editor.buffer.Cursor.Loc
textEnd := editor.buffer.End()
Expand Down

0 comments on commit c66351b

Please sign in to comment.