Skip to content

Commit 941d41e

Browse files
committed
v0.9.2 update~
FIX: Fixed some issues with card pinning. FIX: Cards now properly are pinned when loading projects. (This wasn't working properly, sorry!) QoL: Adding keybinding shortcut to cycle capitalization for highlighted text. QoL: Clicking and highlighting a word and then dragging will highlight whole words, like most text editors (there's a little work to be done here still). INTERNAL FIX: itch.io build script wasn't working properly.
1 parent 0ab22b5 commit 941d41e

8 files changed

Lines changed: 276 additions & 180 deletions

File tree

build_script/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func publishToItch() {
209209

210210
dirCount := len(strings.Split(path, string(os.PathSeparator)))
211211

212-
if info.IsDir() && dirCount == 2 {
212+
if info != nil && info.IsDir() && dirCount == 2 {
213213
buildNames = append(buildNames, path) // We want to upload the build directories
214214
}
215215

card.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,16 +1806,6 @@ func (card *Card) Deserialize(data string) {
18061806
// }
18071807
// }
18081808

1809-
card.Unpin()
1810-
1811-
if gjson.Get(data, "pinned").Exists() {
1812-
pinnedToID := gjson.Get(data, "pinned").Int()
1813-
pin := card.Page.CardByID(pinnedToID)
1814-
if pin != nil {
1815-
card.PinTo(pin)
1816-
}
1817-
}
1818-
18191809
// Set Rect Position and Size before deserializing properties and setting contents so the contents can know the actual correct, current size of the Card (important for Map Contents)
18201810
card.Recreate(float32(rect.Get("W").Float()), float32(rect.Get("H").Float()))
18211811

@@ -1833,6 +1823,16 @@ func (card *Card) Deserialize(data string) {
18331823

18341824
card.LockPosition() // We call this to lock the position of the card, but also to update the Card's position on the underlying Grid.
18351825

1826+
card.Unpin()
1827+
1828+
if gjson.Get(data, "pinned").Exists() {
1829+
1830+
pinnedToID := gjson.Get(data, "pinned").Int()
1831+
pin := card.Page.CardByLoadedID(pinnedToID)
1832+
if pin != nil {
1833+
card.PinTo(pin)
1834+
}
1835+
}
18361836
}
18371837

18381838
func (card *Card) Select() {
@@ -1951,6 +1951,10 @@ func (card *Card) Unpin() {
19511951
}
19521952

19531953
func (card *Card) PinTo(other *Card) {
1954+
if card == other || (other.ContentType != ContentTypeMap && other.ContentType != ContentTypeImage) {
1955+
return
1956+
}
1957+
19541958
card.Unpin()
19551959

19561960
if other.PinnedTo == card {

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# v0.9.2
2+
3+
FIX: Some issues with card pinning.
4+
FIX: Cards now properly are pinned when loading projects.
5+
QoL: Adding keybinding shortcut to cycle capitalization for highlighted text.
6+
QoL: Clicking and highlighting a word and then dragging will highlight whole words, like most text editors (there's a little work to be done here still).
7+
18
# v0.9.1
29

310
## Quality of Life Updates

contents.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,47 +2811,52 @@ func (mc *MapContents) Update() {
28112811
} else if globals.Keybindings.Pressed(KBMapWrapAroundCards) {
28122812
globals.Keybindings.Shortcuts[KBMapWrapAroundCards].ConsumeKeys()
28132813

2814-
set := false
2814+
wrap := false
28152815
x := float32(0)
28162816
y := float32(0)
28172817
x2 := float32(0)
28182818
y2 := float32(0)
28192819

2820-
for _, c := range mc.Card.PinnedCards {
2821-
c.Unpin()
2822-
}
2823-
28242820
for card := range mc.Card.Page.Selection.Cards {
28252821

28262822
if card == mc.Card {
28272823
continue
28282824
}
28292825

2830-
card.Unpin()
2831-
card.PinTo(mc.Card)
2832-
card.Page.Raise(card)
2833-
2834-
if !set || card.Rect.X < x {
2826+
if !wrap || card.Rect.X < x {
28352827
x = card.Rect.X
28362828
}
28372829

2838-
if !set || card.Rect.Y < y {
2830+
if !wrap || card.Rect.Y < y {
28392831
y = card.Rect.Y
28402832
}
28412833

2842-
if !set || card.Rect.X+card.Rect.W > x2 {
2834+
if !wrap || card.Rect.X+card.Rect.W > x2 {
28432835
x2 = card.Rect.X + card.Rect.W
28442836
}
28452837

2846-
if !set || card.Rect.Y+card.Rect.H > y2 {
2838+
if !wrap || card.Rect.Y+card.Rect.H > y2 {
28472839
y2 = card.Rect.Y + card.Rect.H
28482840
}
28492841

2850-
set = true
2842+
wrap = true
28512843

28522844
}
28532845

2854-
if set {
2846+
pinnedCards := append([]*Card{}, mc.Card.PinnedCards...)
2847+
2848+
if wrap {
2849+
2850+
for _, c := range pinnedCards {
2851+
c.Unpin()
2852+
}
2853+
2854+
for card := range mc.Card.Page.Selection.Cards {
2855+
card.Unpin()
2856+
card.PinTo(mc.Card)
2857+
card.Page.Raise(card)
2858+
}
2859+
28552860
mc.Card.Rect.X = x - globals.GridSize
28562861
mc.Card.Rect.Y = y - globals.GridSize
28572862
mc.Card.Rect.W = (x2 - x) + (globals.GridSize * 2)
@@ -2865,7 +2870,7 @@ func (mc *MapContents) Update() {
28652870
globals.EventLog.Log("Wrapped Map to surround and pin selected cards.", false)
28662871
} else {
28672872

2868-
for _, c := range mc.Card.PinnedCards {
2873+
for _, c := range pinnedCards {
28692874
c.Unpin()
28702875
}
28712876

gui.go

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"sort"
1414
"strconv"
1515
"strings"
16+
"unicode"
1617

1718
"github.com/Zyko0/go-sdl3/sdl"
1819
"github.com/tanema/gween"
@@ -1539,7 +1540,9 @@ type Label struct {
15391540
Editing bool
15401541
DrawLineUnderTitle bool
15411542

1542-
Selection *TextSelection
1543+
Selection *TextSelection
1544+
SelectWordIndexStart int
1545+
SelectWordIndexEnd int
15431546

15441547
RegexString string
15451548

@@ -1854,13 +1857,15 @@ func (label *Label) Update() {
18541857
lineText = append(lineText, ' ') // We add a space so you can position the click at the end
18551858
}
18561859

1857-
for _, c := range lineText {
1860+
for i, c := range lineText {
18581861

18591862
diff := pos.DistanceSquared(mousePos)
18601863
if dist < 0 || diff < dist {
18611864
if float32(math.Abs(float64(pos.Y-mousePos.Y))) < globals.GridSize/2 {
1862-
closestIndex = cIndex
1863-
dist = diff
1865+
if label.SelectWordIndexStart == -1 || (c == '\n' || c == ' ' || i == 0) {
1866+
closestIndex = cIndex
1867+
dist = diff
1868+
}
18641869
}
18651870
}
18661871

@@ -1886,7 +1891,19 @@ func (label *Label) Update() {
18861891
if button.Pressed() {
18871892
label.Selection.Select(closestIndex, closestIndex)
18881893
} else if button.Held() && globals.Mouse.Moving() {
1889-
label.Selection.Select(label.Selection.Start, closestIndex)
1894+
if label.SelectWordIndexStart >= 0 {
1895+
start := label.SelectWordIndexStart
1896+
end := label.SelectWordIndexEnd
1897+
if closestIndex > label.SelectWordIndexEnd {
1898+
end = closestIndex
1899+
} else if closestIndex < label.SelectWordIndexStart {
1900+
start = closestIndex
1901+
end = label.SelectWordIndexEnd
1902+
}
1903+
label.Selection.Select(start, end)
1904+
} else {
1905+
label.Selection.Select(label.Selection.Start, closestIndex)
1906+
}
18901907
}
18911908
}
18921909

@@ -1909,6 +1926,9 @@ func (label *Label) Update() {
19091926

19101927
label.Selection.Select(startOfWord, endOfWord)
19111928

1929+
label.SelectWordIndexStart = label.Selection.Start
1930+
label.SelectWordIndexEnd = label.Selection.End
1931+
19121932
} else if button.PressedTimes(3) {
19131933
// label.Selection.Select(0, len(label.Text))
19141934

@@ -1974,6 +1994,52 @@ func (label *Label) Update() {
19741994
clipboard.Write(clipboard.FmtText, []byte(string(text)))
19751995
}
19761996

1997+
if globals.Keybindings.Pressed(KBCycleCaps) {
1998+
text := string(label.SelectedChars())
1999+
start := label.Selection.Start
2000+
end := label.Selection.End
2001+
2002+
isUppercase := strings.ToUpper(text) == text
2003+
isLowercase := strings.ToLower(text) == text
2004+
// isTitlecase := strings.ToTitle(text) == text
2005+
2006+
if len(strings.TrimSpace(text)) == 1 {
2007+
2008+
if isUppercase {
2009+
label.DeleteSelectedChars()
2010+
label.InsertRunesAtIndex([]rune(strings.ToLower(text)), label.Selection.Start)
2011+
} else if isLowercase {
2012+
label.DeleteSelectedChars()
2013+
label.InsertRunesAtIndex([]rune(strings.ToUpper(text)), label.Selection.Start)
2014+
}
2015+
2016+
} else {
2017+
2018+
if isUppercase {
2019+
label.DeleteSelectedChars()
2020+
label.InsertRunesAtIndex([]rune(strings.ToLower(text)), label.Selection.Start)
2021+
} else if isLowercase {
2022+
// First Letter Capitalized Of Each Word
2023+
label.DeleteSelectedChars()
2024+
mod := []rune(text)
2025+
for i, r := range mod {
2026+
if i == 0 || unicode.IsSpace(rune(text[i-1])) {
2027+
mod[i] = rune(strings.ToUpper(string(r))[0])
2028+
}
2029+
}
2030+
label.InsertRunesAtIndex(mod, label.Selection.Start)
2031+
} else {
2032+
label.DeleteSelectedChars()
2033+
label.InsertRunesAtIndex([]rune(strings.ToUpper(text)), label.Selection.Start)
2034+
}
2035+
2036+
}
2037+
2038+
label.Selection.Start = start
2039+
label.Selection.End = end
2040+
2041+
}
2042+
19772043
if globals.Keybindings.Pressed(KBPasteText) {
19782044
if text := clipboard.Read(clipboard.FmtText); text != nil {
19792045
label.DeleteSelectedChars()
@@ -2074,6 +2140,10 @@ func (label *Label) Update() {
20742140

20752141
}
20762142

2143+
if !label.Editing || globals.Mouse.Button(sdl.BUTTON_LEFT).ReleasedRaw() {
2144+
label.SelectWordIndexStart = -1
2145+
}
2146+
20772147
if !label.Editing && label.Editable && mousePos.Inside(label.Rect) {
20782148
rect := label.Rectangle()
20792149
rect.Y++
@@ -2478,6 +2548,11 @@ func (label *Label) TextSize() Vector {
24782548
return globals.TextRenderer.MeasureText(label.Text, 1)
24792549
}
24802550

2551+
func (label *Label) SelectedChars() []rune {
2552+
start, end := label.Selection.ContiguousRange()
2553+
return label.Text[start:end]
2554+
}
2555+
24812556
func (label *Label) DeleteSelectedChars() {
24822557
start, end := label.Selection.ContiguousRange()
24832558
label.DeleteChars(start, end)

keybindings.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ const (
9393
KBCopyText = "Textbox: Copy Selected Text"
9494
KBCutText = "Textbox: Cut Selected Text"
9595
KBPasteText = "Textbox: Paste Copied Text"
96+
KBCycleCaps = "Textbox: Cycle Capitalization"
9697
KBSelectAllText = "Textbox: Select All Text"
9798

9899
KBSwitchWrapMode = "Card Text Editing: Switch Wrap Mode"
@@ -527,6 +528,7 @@ func (kb *Keybindings) Default() {
527528
kb.DefineKeyShortcut(KBCopyText, SDLK_C, SDLK_LCTRL)
528529
kb.DefineKeyShortcut(KBCutText, SDLK_X, SDLK_LCTRL)
529530
kb.DefineKeyShortcut(KBPasteText, SDLK_V, SDLK_LCTRL)
531+
kb.DefineKeyShortcut(KBCycleCaps, SDLK_R, SDLK_LCTRL)
530532
kb.DefineKeyShortcut(KBSelectAllText, SDLK_A, SDLK_LCTRL)
531533

532534
kb.DefineKeyShortcut(KBSwitchWrapMode, SDLK_W, SDLK_LCTRL)

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func init() {
5353

5454
runtime.LockOSThread()
5555

56-
globals.Version = semver.MustParse("0.9.1")
56+
globals.Version = semver.MustParse("0.9.2")
5757
globals.Keyboard = NewKeyboard()
5858
globals.Mouse = NewMouse()
5959
nm := NewMouse()

0 commit comments

Comments
 (0)