fix: Improve divider dragging responsiveness and mouse handling
This commit is contained in:
parent
494d25bf1b
commit
d27563742e
|
|
@ -99,53 +99,33 @@ def main(stdscr, filename):
|
||||||
except curses.error:
|
except curses.error:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Force a mouse position check every loop iteration while dragging
|
# Set timeout for more responsive updates during dragging
|
||||||
|
if dragging_divider:
|
||||||
|
stdscr.timeout(1) # Very short timeout for responsive updates
|
||||||
|
else:
|
||||||
|
stdscr.timeout(-1) # Blocking mode when not dragging
|
||||||
|
|
||||||
|
# Handle divider dragging - check mouse position every iteration when dragging
|
||||||
if dragging_divider:
|
if dragging_divider:
|
||||||
# Set a very short timeout to make the UI responsive
|
|
||||||
stdscr.timeout(1)
|
|
||||||
try:
|
try:
|
||||||
|
# Get current mouse position
|
||||||
|
curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
|
||||||
_, mx, my, _, bstate = curses.getmouse()
|
_, mx, my, _, bstate = curses.getmouse()
|
||||||
|
|
||||||
# Always update divider position while dragging
|
# Update divider position based on mouse x position
|
||||||
min_col = 10
|
min_col = 10
|
||||||
max_col = width - 20 # leave space for right pane
|
max_col = width - 20 # leave space for right pane
|
||||||
divider_col = max(min_col, min(mx, max_col))
|
divider_col = max(min_col, min(mx, max_col))
|
||||||
|
|
||||||
# Check for mouse button release
|
# Check if mouse button has been released
|
||||||
if bstate & curses.BUTTON1_RELEASED or not (bstate & curses.BUTTON1_PRESSED):
|
if not (bstate & curses.BUTTON1_PRESSED):
|
||||||
dragging_divider = False
|
dragging_divider = False
|
||||||
stdscr.timeout(-1) # Reset to blocking mode when done dragging
|
|
||||||
except curses.error:
|
except curses.error:
|
||||||
# If we can't get mouse state, try again on next iteration
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#
|
# Exit on 'q' or ESC
|
||||||
# # Mouse click changes focus
|
if key in [ord('q'), 27]:
|
||||||
# if key == curses.KEY_MOUSE:
|
break
|
||||||
# try:
|
|
||||||
# _, mx, my, _, bstate = curses.getmouse()
|
|
||||||
#
|
|
||||||
# if bstate & curses.BUTTON1_PRESSED:
|
|
||||||
# if dragging_divider:
|
|
||||||
# # Update divider while dragging
|
|
||||||
# min_col = 10
|
|
||||||
# max_col = width - 20 # leave space for right pane
|
|
||||||
# divider_col = max(min_col, min(mx, max_col))
|
|
||||||
# elif mx == divider_col:
|
|
||||||
# dragging_divider = True
|
|
||||||
#
|
|
||||||
# elif bstate & curses.BUTTON1_RELEASED:
|
|
||||||
# dragging_divider = False
|
|
||||||
#
|
|
||||||
# elif bstate & curses.BUTTON1_CLICKED:
|
|
||||||
# focus = "left" if mx < divider_col else "right"
|
|
||||||
#
|
|
||||||
# except curses.error:
|
|
||||||
# pass
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# elif key in [ord('q'), 27]:
|
|
||||||
# break
|
|
||||||
|
|
||||||
# Left pane movement
|
# Left pane movement
|
||||||
elif focus == "left":
|
elif focus == "left":
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue