From 2af45ad69170af0a4fd9c0bdf4fb6d23010a5672 Mon Sep 17 00:00:00 2001 From: SolarLune Date: Mon, 6 Nov 2023 13:32:20 -0800 Subject: [PATCH] QoL Improvements. Adding keyboard shortcut to create a new Card of the previous type. This shortcut is usable while typing in a description. INTERNAL: Adding Shortcut.TempOverride. This is used to force a shortcut to be seen as being "pressed", even if that's not the case ordinarily. FIX: Keybindings search area no longer accepts newlines. --- common.go | 1 + gui.go | 7 ++++++- keybindings.go | 14 ++++++++++---- main.go | 6 ++++++ project.go | 17 +++++++++++++++++ todo | 11 ++++++++++- 6 files changed, 50 insertions(+), 6 deletions(-) diff --git a/common.go b/common.go index b29ee2e..3d7b1bd 100644 --- a/common.go +++ b/common.go @@ -877,6 +877,7 @@ func placeCardInStack(card *Card, centerIfNoSelection bool) { for _, t := range selection[0].Stack.Tail() { t.Rect.Y += card.Rect.H t.LockPosition() + globals.Project.UndoHistory.Capture(NewUndoState(t)) } card.LockPosition() globals.Project.Camera.FocusOn(false, card) diff --git a/gui.go b/gui.go index 0aeba6d..7409b54 100644 --- a/gui.go +++ b/gui.go @@ -1419,6 +1419,11 @@ func (label *Label) MoveCaretBackOneWord() int { func (label *Label) Update() { + if label.Editing && globals.Keybindings.Pressed(KBNewCardOfPrevType) { + label.EndEditing() + return + } + clickedOut := false if label.HorizontalAlignment == AlignCenter { @@ -1793,7 +1798,7 @@ func (label *Label) Update() { } // Typing - if len(globals.InputText) > 0 { + if !clickedOut && len(globals.InputText) > 0 { label.DeleteSelectedChars() label.InsertRunesAtIndex(globals.InputText, label.Selection.CaretPos) label.Selection.AdvanceCaret(len(globals.InputText)) diff --git a/keybindings.go b/keybindings.go index da9c417..5780ffb 100644 --- a/keybindings.go +++ b/keybindings.go @@ -88,7 +88,8 @@ const ( KBPasteText = "Textbox: Paste Copied Text" KBSelectAllText = "Textbox: Select All Text" - KBSwitchWrapMode = "Card Text Editing: Switch Wrap Mode" + KBSwitchWrapMode = "Card Text Editing: Switch Wrap Mode" + KBNewCardOfPrevType = "Create New Card of Prev. Type" KBUndo = "Undo" KBRedo = "Redo" @@ -219,8 +220,9 @@ type Shortcut struct { triggerMode int MouseButton uint8 DefaultMouseButton uint8 + DefaultSet bool - DefaultSet bool + TempOverride bool } func NewShortcut(name string) *Shortcut { @@ -396,7 +398,6 @@ func NewKeybindings() *Keybindings { MouseShortcutsByFamily: map[uint8][]*Shortcut{}, } kb.Default() - kb.UpdateShortcutFamilies() return kb } @@ -482,6 +483,7 @@ func (kb *Keybindings) Default() { kb.DefineKeyShortcut(KBNewSubpageCard, sdl.K_8, sdl.K_LSHIFT) kb.DefineKeyShortcut(KBNewLinkCard, sdl.K_9, sdl.K_LSHIFT) kb.DefineKeyShortcut(KBNewTableCard, sdl.K_0, sdl.K_LSHIFT) + kb.DefineKeyShortcut(KBNewCardOfPrevType, sdl.K_RETURN, sdl.K_LCTRL) kb.DefineKeyShortcut(KBAddToSelection, sdl.K_LSHIFT).triggerMode = TriggerModeHold kb.DefineKeyShortcut(KBRemoveFromSelection, sdl.K_LALT).triggerMode = TriggerModeHold @@ -513,7 +515,7 @@ func (kb *Keybindings) Default() { kb.DefineKeyShortcut(KBWindowSizeSmall, sdl.K_F9) kb.DefineKeyShortcut(KBWindowSizeNormal, sdl.K_F10) - kb.DefineKeyShortcut(KBToggleFullscreen, sdl.K_RETURN, sdl.K_LCTRL) + kb.DefineKeyShortcut(KBToggleFullscreen, sdl.K_RETURN, sdl.K_LALT) kb.DefineKeyShortcut(KBUnlockImageASR, sdl.K_LSHIFT).triggerMode = TriggerModeHold kb.DefineKeyShortcut(KBCheckboxToggleCompletion, sdl.K_SPACE) @@ -619,6 +621,10 @@ func (kb *Keybindings) Pressed(bindingName string) bool { return false } + if sc.TempOverride { + return true + } + if sc.MouseButton < 255 { for _, familyShortcut := range kb.MouseShortcutsByFamily[sc.MouseButton] { diff --git a/main.go b/main.go index b3b1049..10e0d41 100644 --- a/main.go +++ b/main.go @@ -745,6 +745,10 @@ func main() { HandleFontReload() + for _, s := range globals.Keybindings.Shortcuts { + s.TempOverride = false + } + } if globals.Settings.Get(SettingsSaveWindowPosition).AsBool() { @@ -2449,6 +2453,8 @@ where the cursor is over the window.`)) row.Add("search label", NewLabel("Search: ", nil, false, AlignLeft)) searchKeybindingsLabel := NewLabel("test", &sdl.FRect{0, 0, 380, 32}, false, AlignLeft) searchKeybindingsLabel.Editable = true + searchKeybindingsLabel.RegexString = RegexNoNewlines + // searchKeybindingsLabel.AutoExpand = true searchKeybindingsLabel.OnChange = func() { diff --git a/project.go b/project.go index 81bb2e8..1796b0a 100644 --- a/project.go +++ b/project.go @@ -1337,6 +1337,23 @@ func (project *Project) GlobalShortcuts() { } + if kb.Pressed(KBNewCardOfPrevType) && (globals.State == StateNeutral || globals.State == StateMapEditing || globals.State == StateTextEditing) { + newCard := project.CurrentPage.CreateNewCard(project.LastCardType) + kb.Shortcuts[KBNewCardOfPrevType].ConsumeKeys() + placeCardInStack(newCard, false) + project.CurrentPage.Selection.Clear() + project.CurrentPage.Selection.Add(newCard) + + // Trigger text editing for this new card and update it by triggering all possible shortcuts for text editing. TODO: Clean this up. + kb.Shortcuts[KBCheckboxEditText].TempOverride = true + kb.Shortcuts[KBLinkEditText].TempOverride = true + kb.Shortcuts[KBNoteEditText].TempOverride = true + kb.Shortcuts[KBNumberedEditText].TempOverride = true + kb.Shortcuts[KBTimerEditText].TempOverride = true + kb.Shortcuts[KBSubpageEditText].TempOverride = true + newCard.Update() + } + if globals.State == StateNeutral || globals.State == StateMapEditing || globals.State == StateCardArrow { kb := globals.Keybindings diff --git a/todo b/todo index f1655a7..4b083ed 100644 --- a/todo +++ b/todo @@ -1,8 +1,16 @@ [x] Editing card pushes lower cards up [x] Taking screenshots crash MP [x] Can't go up sub-pages via keybinding while in Link Mode + +[ ] Deleting cards should move the rest of the cards up (new shortcut?) +[ ] Show shortcut collisions in input menu +[ ] Give message on start-up when there's a shortcut collision [ ] Link text is essentially blank -[ ] AMD cards might have minor graphical glitches? Mainly in main menu +[ ] Investigate web - maybe I can render a website to an image and then link to it? - chromedp to have an actual visible website? +[ ] State testing could be drastically simplified +[ ] Consolidate card contents text editing (see project.go:1348) + +[ ] AMD cards might have MAJOR graphical glitches? Mainly in main menu [ ] Menu shadows are way too dark [x] It does not like cutting and pasting a sub-card into itself. @@ -84,6 +92,7 @@ [x] Make it so if images surpass the GPU's maximum texture size, they get sized down [x] What should we do if we're using media from another drive? [ ] Optimize - seems like there's a memory leak somewhere + [ ] Loop through slices to perform a function instead of making a duplicate slice to iterate through [ ] Show keybinding conflicts in the Keybindings menu [x] Make all text fields in Cards (like their title / description) consistent in terms of their capabilities [ ] Fix storing a card in collapsed mode doesn't allow it to become uncollapsed; guess we'll need to store the uncollapsed size to revert to.