Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 43 additions & 21 deletions editor_workspace.v
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct EditorWorkspaceModel {
// the only way we can change the mode is by exiting the current scope with a command to do so
mode Mode
mut:
tmux_wrapped bool
dialog_model ?DebuggableModel

active_editor_id int
Expand Down Expand Up @@ -59,7 +60,7 @@ fn EditorWorkspaceModel.new(initial_file_path string) EditorWorkspaceModel {

fn (mut m EditorWorkspaceModel) init() ?tea.Cmd {
m.input_field = boba.InputField.new_with_prefix(":", 0)
return tea.batch(open_editor(m.initial_file_path))
return tea.batch(open_editor(m.initial_file_path), check_if_tmux_wrapped)
}

struct SwitchModeMsg {
Expand Down Expand Up @@ -253,32 +254,49 @@ fn (mut m EditorWorkspaceModel) update(msg tea.Msg) (tea.Model, ?tea.Cmd) {
// move to previous split (left)
if m.split_tree.count() > 1 {
old_id := m.split_tree.active_editor_id
m.split_tree.navigate_prev()
new_id := m.split_tree.active_editor_id
m.active_editor_id = new_id

cmds << tea.sequence(
unfocus_editor(old_id),
focus_editor(new_id),
query_editor_data(new_id),
query_pwd_git_branch
)
moved := m.split_tree.navigate_prev(m.tmux_wrapped)

if moved == false {
os.execute('tmux select-pane -L')
} else {
new_id := m.split_tree.active_editor_id
m.active_editor_id = new_id

cmds << tea.sequence(
unfocus_editor(old_id),
focus_editor(new_id),
query_editor_data(new_id),
query_pwd_git_branch
)
}
} else {
if m.tmux_wrapped {
os.execute('tmux select-pane -L')
}
}
}
"ctrl+w+l" {
// move to next split (right)
if m.split_tree.count() > 1 {
old_id := m.split_tree.active_editor_id
m.split_tree.navigate_next()
new_id := m.split_tree.active_editor_id
m.active_editor_id = new_id

cmds << tea.sequence(
unfocus_editor(old_id),
focus_editor(new_id),
query_editor_data(new_id),
query_pwd_git_branch
)
moved := m.split_tree.navigate_next(m.tmux_wrapped)
if moved == false {
os.execute('tmux select-pane -R')
} else {
new_id := m.split_tree.active_editor_id
m.active_editor_id = new_id

cmds << tea.sequence(
unfocus_editor(old_id),
focus_editor(new_id),
query_editor_data(new_id),
query_pwd_git_branch
)
}
} else {
if m.tmux_wrapped {
os.execute('tmux select-pane -R')
}
}
}
else {}
Expand Down Expand Up @@ -329,6 +347,10 @@ fn (mut m EditorWorkspaceModel) update(msg tea.Msg) (tea.Model, ?tea.Cmd) {
tea.FocusedMsg {
cmds << query_pwd_git_branch
}
CheckIfTMUXWrappedMsg {
m.tmux_wrapped = os.getenv("TMUX").len > 0
assert m.tmux_wrapped
}
OpenDialogMsg {
mut d_model := msg.model
cmd := d_model.init()
Expand Down
6 changes: 6 additions & 0 deletions petal.v
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ fn (mut m PetalModel) on_toggle_debug_screen() (tea.Model, ?tea.Cmd) {
return m.clone(), none
}

struct CheckIfTMUXWrappedMsg {}

fn check_if_tmux_wrapped() tea.Msg {
return CheckIfTMUXWrappedMsg{}
}

fn (mut m PetalModel) update(msg tea.Msg) (tea.Model, ?tea.Cmd) {
mut cmds := []tea.Cmd{}
match msg {
Expand Down
22 changes: 21 additions & 1 deletion splash_screen.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module main

import math
import os
import tauraamui.bobatea as tea
import palette

Expand All @@ -21,6 +22,7 @@ struct SplashScreenModel {
leader_key string
logo SplashLogo
mut:
tmux_wrapped bool
leader_mode bool
leader_data string
dialog_model ?DebuggableModel
Expand All @@ -36,7 +38,7 @@ fn SplashScreenModel.new() SplashScreenModel {
}

fn (mut m SplashScreenModel) init() ?tea.Cmd {
return none
return check_if_tmux_wrapped
}

fn (mut m SplashScreenModel) handle_escape() (tea.Model, ?tea.Cmd) {
Expand Down Expand Up @@ -75,6 +77,9 @@ fn (mut m SplashScreenModel) update(msg tea.Msg) (tea.Model, ?tea.Cmd) {
}

match msg {
CheckIfTMUXWrappedMsg {
m.tmux_wrapped = os.getenv("TMUX").len > 0
}
tea.KeyMsg {
match msg.k_type {
.special {
Expand All @@ -85,6 +90,20 @@ fn (mut m SplashScreenModel) update(msg tea.Msg) (tea.Model, ?tea.Cmd) {
'ctrl+c' {
return m.handle_escape()
}
'ctrl+w+h' {
$if !darwin {
if m.tmux_wrapped {
os.execute('tmux select-pane -L')
}
}
}
'ctrl+w+l' {
$if !darwin {
if m.tmux_wrapped {
os.execute('tmux select-pane -R')
}
}
}
else {}
}
}
Expand Down Expand Up @@ -351,6 +370,7 @@ fn (m SplashScreenModel) debug_data() DebugData {
name: 'splash_screen data'
data: {
'leader key': m.leader_key
'tmux wrapped': '${m.tmux_wrapped}'
'': if d := m.dialog_model { d.debug_data() } else { 'null' }
'version': '${version} - (${build_id})'
}
Expand Down
20 changes: 14 additions & 6 deletions split_tree.v
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ fn (t SplitTree) collect_editor_ids(node SplitNode) []int {
}

// Navigate to next editor
pub fn (mut t SplitTree) navigate_next() bool {
pub fn (mut t SplitTree) navigate_next(do_not_wrap_around bool) bool {
all_ids := t.get_all_editor_ids()
if all_ids.len <= 1 {
return false
Expand All @@ -238,13 +238,17 @@ pub fn (mut t SplitTree) navigate_next() bool {
return true
}

next_idx := (current_idx + 1) % all_ids.len
if do_not_wrap_around && current_idx == all_ids.len - 1 {
return false
}

next_idx := if do_not_wrap_around { current_idx + 1 } else { (current_idx + 1) % all_ids.len }
t.active_editor_id = all_ids[next_idx]
return true
}

// Navigate to previous editor
pub fn (mut t SplitTree) navigate_prev() bool {
pub fn (mut t SplitTree) navigate_prev(do_not_wrap_around bool) bool {
all_ids := t.get_all_editor_ids()
if all_ids.len <= 1 {
return false
Expand All @@ -256,7 +260,11 @@ pub fn (mut t SplitTree) navigate_prev() bool {
return true
}

prev_idx := (current_idx - 1 + all_ids.len) % all_ids.len
if current_idx == 0 {
return false
}

prev_idx := if do_not_wrap_around { current_idx - 1 } else { (current_idx - 1 + all_ids.len) % all_ids.len }
t.active_editor_id = all_ids[prev_idx]
return true
}
Expand Down Expand Up @@ -358,11 +366,11 @@ pub fn (mut t SplitTree) close_active_split() bool {

if root := t.root {
// navigate to next before closing
t.navigate_next()
t.navigate_next(false)

// if we're still on the same ID after navigation, try previous
if t.active_editor_id == old_active_id {
t.navigate_prev()
t.navigate_prev(false)
}

t.root = t.remove_editor_from_node(root, old_active_id)
Expand Down