7e513926ba02dae7fbc33c2cf73e9fbd43a7e1fd

Author
Ayman Bagabas <ayman.bagabas@gmail.com>
Committer
Ayman Bagabas <ayman.bagabas@gmail.com>
Date

Message

refactor: use KeyPressMsg and MouseClickMsg instead of KeyMsg and MouseMsg

Diff

  1diff --git a/cmd/soft/browse/browse.go b/cmd/soft/browse/browse.go
  2index 4ab28cb2fb84dc30873241d1cf366fe9d73bed35..ecb3d5302d44aebee5147d5540477bd79d4ba6c6 100644
  3--- a/cmd/soft/browse/browse.go
  4+++ b/cmd/soft/browse/browse.go
  5@@ -151,7 +151,7 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
  6 	switch msg := msg.(type) {
  7 	case tea.WindowSizeMsg:
  8 		m.SetSize(msg.Width, msg.Height)
  9-	case tea.KeyMsg:
 10+	case tea.KeyPressMsg:
 11 		switch {
 12 		case key.Matches(msg, m.common.KeyMap.Back) && m.error != nil:
 13 			m.error = nil
 14diff --git a/pkg/ssh/ui.go b/pkg/ssh/ui.go
 15index 89d5ee5f6fe07af8fbd89793319f7d96573e96c8..204b80181e5ea48eefa9a475e9919ad9606367a3 100644
 16--- a/pkg/ssh/ui.go
 17+++ b/pkg/ssh/ui.go
 18@@ -179,37 +179,34 @@ func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 19 				cmds = append(cmds, cmd)
 20 			}
 21 		}
 22-	case tea.KeyMsg, tea.MouseMsg:
 23-		switch msg := msg.(type) {
 24-		case tea.KeyMsg:
 25+	case tea.KeyPressMsg:
 26+		switch {
 27+		case key.Matches(msg, ui.common.KeyMap.Back) && ui.error != nil:
 28+			ui.error = nil
 29+			ui.state = readyState
 30+			// Always show the footer on error.
 31+			ui.showFooter = ui.footer.ShowAll()
 32+		case key.Matches(msg, ui.common.KeyMap.Help):
 33+			cmds = append(cmds, footer.ToggleFooterCmd)
 34+		case key.Matches(msg, ui.common.KeyMap.Quit):
 35+			if !ui.IsFiltering() {
 36+				// Stop bubblezone background workers.
 37+				ui.common.Zone.Close()
 38+				return ui, tea.Quit
 39+			}
 40+		case ui.activePage == repoPage &&
 41+			ui.pages[ui.activePage].(*repo.Repo).Path() == "" &&
 42+			key.Matches(msg, ui.common.KeyMap.Back):
 43+			ui.activePage = selectionPage
 44+			// Always show the footer on selection page.
 45+			ui.showFooter = true
 46+		}
 47+	case tea.MouseClickMsg:
 48+		switch msg.Mouse().Button {
 49+		case tea.MouseLeft:
 50 			switch {
 51-			case key.Matches(msg, ui.common.KeyMap.Back) && ui.error != nil:
 52-				ui.error = nil
 53-				ui.state = readyState
 54-				// Always show the footer on error.
 55-				ui.showFooter = ui.footer.ShowAll()
 56-			case key.Matches(msg, ui.common.KeyMap.Help):
 57+			case ui.common.Zone.Get("footer").InBounds(msg):
 58 				cmds = append(cmds, footer.ToggleFooterCmd)
 59-			case key.Matches(msg, ui.common.KeyMap.Quit):
 60-				if !ui.IsFiltering() {
 61-					// Stop bubblezone background workers.
 62-					ui.common.Zone.Close()
 63-					return ui, tea.Quit
 64-				}
 65-			case ui.activePage == repoPage &&
 66-				ui.pages[ui.activePage].(*repo.Repo).Path() == "" &&
 67-				key.Matches(msg, ui.common.KeyMap.Back):
 68-				ui.activePage = selectionPage
 69-				// Always show the footer on selection page.
 70-				ui.showFooter = true
 71-			}
 72-		case tea.MouseClickMsg:
 73-			switch msg.Mouse().Button {
 74-			case tea.MouseLeft:
 75-				switch {
 76-				case ui.common.Zone.Get("footer").InBounds(msg):
 77-					cmds = append(cmds, footer.ToggleFooterCmd)
 78-				}
 79 			}
 80 		}
 81 	case footer.ToggleFooterMsg:
 82diff --git a/pkg/ui/components/selector/selector.go b/pkg/ui/components/selector/selector.go
 83index ff43816bb5fd6dd749008fee496b014085b5c8a7..e42ee3507a674a36561ae9255a7b6ea5f2e25c86 100644
 84--- a/pkg/ui/components/selector/selector.go
 85+++ b/pkg/ui/components/selector/selector.go
 86@@ -252,7 +252,7 @@ func (s *Selector) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 87 				}
 88 			}
 89 		}
 90-	case tea.KeyMsg:
 91+	case tea.KeyPressMsg:
 92 		filterState := s.FilterState()
 93 		switch {
 94 		case key.Matches(msg, s.common.KeyMap.Help):
 95diff --git a/pkg/ui/components/tabs/tabs.go b/pkg/ui/components/tabs/tabs.go
 96index 51aec590e5c06da697408cb89ef2ffbb586e5853..36f0a19e85c2bda3dc172e02d8b5bb5b70919ad4 100644
 97--- a/pkg/ui/components/tabs/tabs.go
 98+++ b/pkg/ui/components/tabs/tabs.go
 99@@ -54,7 +54,7 @@ func (t *Tabs) Init() tea.Cmd {
100 func (t *Tabs) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
101 	cmds := make([]tea.Cmd, 0)
102 	switch msg := msg.(type) {
103-	case tea.KeyMsg:
104+	case tea.KeyPressMsg:
105 		switch msg.String() {
106 		case "tab":
107 			t.activeTab = (t.activeTab + 1) % len(t.tabs)
108diff --git a/pkg/ui/components/viewport/viewport.go b/pkg/ui/components/viewport/viewport.go
109index c2355ae76b143eac896bd26ffed00e561bbab73e..ccbd2318488ecefb140a0a8838ae01b273e8ee46 100644
110--- a/pkg/ui/components/viewport/viewport.go
111+++ b/pkg/ui/components/viewport/viewport.go
112@@ -40,7 +40,7 @@ func (v *Viewport) Init() tea.Cmd {
113 // Update implements tea.Model.
114 func (v *Viewport) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
115 	switch msg := msg.(type) {
116-	case tea.KeyMsg:
117+	case tea.KeyPressMsg:
118 		switch {
119 		case key.Matches(msg, v.common.KeyMap.GotoTop):
120 			v.GotoTop()
121diff --git a/pkg/ui/pages/repo/files.go b/pkg/ui/pages/repo/files.go
122index 7a73750b06abe63897a5f2df7688b262be516222..24275396a925976ebcd0d0babe0690bc34dc707d 100644
123--- a/pkg/ui/pages/repo/files.go
124+++ b/pkg/ui/pages/repo/files.go
125@@ -264,7 +264,7 @@ func (f *Files) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
126 		case filesViewFiles, filesViewContent:
127 			cmds = append(cmds, f.deselectItemCmd())
128 		}
129-	case tea.KeyMsg:
130+	case tea.KeyPressMsg:
131 		switch f.activeView {
132 		case filesViewFiles:
133 			switch {
134diff --git a/pkg/ui/pages/repo/filesitem.go b/pkg/ui/pages/repo/filesitem.go
135index d821eb74d3728f72e04f4cf42245fe76182d4045..5c3e560f13f76796d4352dfa8e01030698d28594 100644
136--- a/pkg/ui/pages/repo/filesitem.go
137+++ b/pkg/ui/pages/repo/filesitem.go
138@@ -82,7 +82,7 @@ func (d FileItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
139 		return nil
140 	}
141 	switch msg := msg.(type) {
142-	case tea.KeyMsg:
143+	case tea.KeyPressMsg:
144 		switch {
145 		case key.Matches(msg, d.common.KeyMap.Copy):
146 			return copyCmd(item.entry.Name(), fmt.Sprintf("File name %q copied to clipboard", item.entry.Name()))
147diff --git a/pkg/ui/pages/repo/log.go b/pkg/ui/pages/repo/log.go
148index bb8caa34c4d4b2d6f915ae0a5411d4388b6f24bf..d58118246f2af89de24ecb4e13be368a1b1828c0 100644
149--- a/pkg/ui/pages/repo/log.go
150+++ b/pkg/ui/pages/repo/log.go
151@@ -221,11 +221,11 @@ func (l *Log) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
152 		if i != nil {
153 			l.activeCommit = i.(LogItem).Commit
154 		}
155-	case tea.KeyMsg, tea.MouseMsg:
156+	case tea.KeyPressMsg, tea.MouseClickMsg:
157 		switch l.activeView {
158 		case logViewCommits:
159 			switch kmsg := msg.(type) {
160-			case tea.KeyMsg:
161+			case tea.KeyPressMsg:
162 				switch {
163 				case key.Matches(kmsg, l.common.KeyMap.SelectItem):
164 					cmds = append(cmds, l.selector.SelectItemCmd)
165@@ -248,7 +248,7 @@ func (l *Log) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
166 			cmds = append(cmds, cmd)
167 		case logViewDiff:
168 			switch kmsg := msg.(type) {
169-			case tea.KeyMsg:
170+			case tea.KeyPressMsg:
171 				switch {
172 				case key.Matches(kmsg, l.common.KeyMap.BackItem):
173 					l.goBack()
174diff --git a/pkg/ui/pages/repo/logitem.go b/pkg/ui/pages/repo/logitem.go
175index d95fe865bb0987c2ed09f2a6bc1a3f7ff922d71e..1aefd53204ac9288fb6f122efdce0ccd69f81256 100644
176--- a/pkg/ui/pages/repo/logitem.go
177+++ b/pkg/ui/pages/repo/logitem.go
178@@ -62,7 +62,7 @@ func (d LogItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
179 		return nil
180 	}
181 	switch msg := msg.(type) {
182-	case tea.KeyMsg:
183+	case tea.KeyPressMsg:
184 		switch {
185 		case key.Matches(msg, d.common.KeyMap.Copy):
186 			return copyCmd(item.Hash(), "Commit hash copied to clipboard")
187diff --git a/pkg/ui/pages/repo/refs.go b/pkg/ui/pages/repo/refs.go
188index f30f8f735d0496d03aba55d08d670e939674c38c..45a6b18d9cd9b33c9590eeca42c49cef5ec3f84f 100644
189--- a/pkg/ui/pages/repo/refs.go
190+++ b/pkg/ui/pages/repo/refs.go
191@@ -152,7 +152,7 @@ func (r *Refs) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
192 				switchTabCmd(&Files{}),
193 			)
194 		}
195-	case tea.KeyMsg:
196+	case tea.KeyPressMsg:
197 		switch {
198 		case key.Matches(msg, r.common.KeyMap.SelectItem):
199 			cmds = append(cmds, r.selector.SelectItemCmd)
200diff --git a/pkg/ui/pages/repo/refsitem.go b/pkg/ui/pages/repo/refsitem.go
201index aaed5e7e51afbadf03579074d43670acd6438879..e89015049de9e83834b44c4bebee012c34d7bfd6 100644
202--- a/pkg/ui/pages/repo/refsitem.go
203+++ b/pkg/ui/pages/repo/refsitem.go
204@@ -83,7 +83,7 @@ func (d RefItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
205 		return nil
206 	}
207 	switch msg := msg.(type) {
208-	case tea.KeyMsg:
209+	case tea.KeyPressMsg:
210 		switch {
211 		case key.Matches(msg, d.common.KeyMap.Copy):
212 			return copyCmd(item.ID(), fmt.Sprintf("Reference %q copied to clipboard", item.ID()))
213diff --git a/pkg/ui/pages/repo/repo.go b/pkg/ui/pages/repo/repo.go
214index 5aba643528281850c17a85e8faef09c5b4dd9b6e..fead336729501513ada5c6d456d58281784f1ddc 100644
215--- a/pkg/ui/pages/repo/repo.go
216+++ b/pkg/ui/pages/repo/repo.go
217@@ -171,7 +171,7 @@ func (r *Repo) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
218 		}
219 	case tabs.ActiveTabMsg:
220 		r.activeTab = int(msg)
221-	case tea.KeyMsg, tea.MouseMsg:
222+	case tea.KeyPressMsg, tea.MouseClickMsg:
223 		t, cmd := r.tabs.Update(msg)
224 		r.tabs = t.(*tabs.Tabs)
225 		if cmd != nil {
226@@ -200,7 +200,7 @@ func (r *Repo) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
227 			}
228 		}
229 		switch msg := msg.(type) {
230-		case tea.KeyMsg:
231+		case tea.KeyPressMsg:
232 			switch {
233 			case key.Matches(msg, r.common.KeyMap.Back):
234 				cmds = append(cmds, goBackCmd)
235@@ -271,7 +271,7 @@ func (r *Repo) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
236 	// Update the status bar on these events
237 	// Must come after we've updated the active tab
238 	switch msg.(type) {
239-	case RepoMsg, RefMsg, tabs.ActiveTabMsg, tea.KeyMsg, tea.MouseMsg,
240+	case RepoMsg, RefMsg, tabs.ActiveTabMsg, tea.KeyPressMsg, tea.MouseClickMsg,
241 		FileItemsMsg, FileContentMsg, FileBlameMsg, selector.ActiveMsg,
242 		LogItemsMsg, GoBackMsg, LogDiffMsg, EmptyRepoMsg,
243 		StashListMsg, StashPatchMsg:
244diff --git a/pkg/ui/pages/repo/stash.go b/pkg/ui/pages/repo/stash.go
245index 37f8a1a85b5341a56884f0cb71c44e71dcc88c4d..9d0b874884c5f21534326468c07b159304070999 100644
246--- a/pkg/ui/pages/repo/stash.go
247+++ b/pkg/ui/pages/repo/stash.go
248@@ -165,7 +165,7 @@ func (s *Stash) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
249 				cmds = append(cmds, cmd)
250 			}
251 		}
252-	case tea.KeyMsg:
253+	case tea.KeyPressMsg:
254 		switch s.state {
255 		case stashStateList:
256 			switch {
257diff --git a/pkg/ui/pages/repo/stashitem.go b/pkg/ui/pages/repo/stashitem.go
258index 77dd1a9274ff09fabdd1afff63f558236658eed3..a094040f992a9e7e70f565f92aaf70e14cfc7155 100644
259--- a/pkg/ui/pages/repo/stashitem.go
260+++ b/pkg/ui/pages/repo/stashitem.go
261@@ -65,7 +65,7 @@ func (d StashItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
262 	}
263 
264 	switch msg := msg.(type) {
265-	case tea.KeyMsg:
266+	case tea.KeyPressMsg:
267 		switch {
268 		case key.Matches(msg, d.common.KeyMap.Copy):
269 			return copyCmd(item.Title(), fmt.Sprintf("Stash message %q copied to clipboard", item.Title()))
270diff --git a/pkg/ui/pages/selection/item.go b/pkg/ui/pages/selection/item.go
271index 4b338bda5d68c44bbf1c7e2a11c38dedda0811f0..7b5b82809f16409c28ccf1666104c2bbf59fbe91 100644
272--- a/pkg/ui/pages/selection/item.go
273+++ b/pkg/ui/pages/selection/item.go
274@@ -135,7 +135,7 @@ func (d *ItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
275 		return nil
276 	}
277 	switch msg := msg.(type) {
278-	case tea.KeyMsg:
279+	case tea.KeyPressMsg:
280 		switch {
281 		case key.Matches(msg, d.common.KeyMap.Copy):
282 			d.copiedIdx = idx
283diff --git a/pkg/ui/pages/selection/selection.go b/pkg/ui/pages/selection/selection.go
284index 3ced323a69c692f446d2988ee54347aab9a1c79d..fdabb15137244b36c27df359f4e9acb9cf8d31b7 100644
285--- a/pkg/ui/pages/selection/selection.go
286+++ b/pkg/ui/pages/selection/selection.go
287@@ -250,9 +250,9 @@ func (s *Selection) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
288 		if cmd != nil {
289 			cmds = append(cmds, cmd)
290 		}
291-	case tea.KeyMsg, tea.MouseMsg:
292+	case tea.KeyPressMsg, tea.MouseMsg:
293 		switch msg := msg.(type) {
294-		case tea.KeyMsg:
295+		case tea.KeyPressMsg:
296 			switch {
297 			case key.Matches(msg, s.common.KeyMap.Back):
298 				cmds = append(cmds, s.selector.Init())