Skip to content

Commit

Permalink
Enable entering vi navigation mode
Browse files Browse the repository at this point in the history
  • Loading branch information
joouha committed May 8, 2022
1 parent 9ed70ca commit afd245e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ Changelog

Notable changes to this project will be documented in this file.

*********************
v1.6.1 - (2022-05-08)
*********************

Changed
=======

- Allow ``file:`` scheme links in markdown

Fixed
=====

- Enable entering vi navigation mode
- Change "go to matching bracket" command key-binding in micro mode to :kbd:`Alt+(` / :kbd:`Alt+)`, so as not to conflict with the "find-next" command

*********************
v1.6.0 - (2022-04-26)
*********************
Expand Down
6 changes: 4 additions & 2 deletions euporie/commands/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging

from prompt_toolkit.filters import buffer_has_focus
from prompt_toolkit.filters import buffer_has_focus, vi_mode, vi_navigation_mode

from euporie.app.current import get_edit_app as get_app
from euporie.commands.registry import add
Expand Down Expand Up @@ -45,7 +45,9 @@ def enter_cell_edit_mode() -> "None":

@add(
keys="escape",
filter=cell_has_focus & buffer_has_focus,
filter=cell_has_focus
& buffer_has_focus
& (~vi_mode | (vi_mode & vi_navigation_mode)),
group="notebook",
)
def exit_edit_mode() -> "None":
Expand Down
14 changes: 12 additions & 2 deletions euporie/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
from prompt_toolkit.filters import (
Condition,
emacs_insert_mode,
emacs_mode,
to_filter,
vi_insert_mode,
vi_mode,
vi_replace_mode,
)

from euporie.app.current import get_edit_app as get_app
Expand Down Expand Up @@ -265,5 +268,12 @@ def kernel_is_python() -> "bool":
)


"""Determine if any binding style is in insert mode"""
insert_mode = vi_insert_mode | emacs_insert_mode | micro_insert_mode
"""Determine if any binding style is in insert mode."""
insert_mode = (
(vi_mode & vi_insert_mode)
| (emacs_mode & emacs_insert_mode)
| (micro_mode & micro_insert_mode)
)

"""Determine if any binding style is in replace mode."""
replace_mode = micro_replace_mode | vi_replace_mode
24 changes: 23 additions & 1 deletion euporie/tabs/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from euporie.app.current import get_edit_app as get_app
from euporie.config import config
from euporie.filters import insert_mode, replace_mode
from euporie.key_binding.bindings.commands import load_command_bindings
from euporie.suggest import KernelAutoSuggest
from euporie.tabs.base import Tab
Expand Down Expand Up @@ -938,7 +939,7 @@ def statusbar_fields(
"""Generates the formatted text for the statusbar."""
return (
[
"^" if self.edit_mode else ">",
self.mode(),
f"Cell {self.page.selected_slice.start+1}",
"Saving.." if self.saving else "",
],
Expand All @@ -947,3 +948,24 @@ def statusbar_fields(
KERNEL_STATUS_REPR[self.kernel.status] if self.kernel else ".",
],
)

def mode(self) -> "str":
"""Returns a symbol representing the current mode.
* ``^``: Notebook mode
* ``>``: Navigation mode
* ``I``: Insert mode
* ``v``: Visual mode
Returns:
A character representing the current mode
"""
# TODO - sort this out
if self.edit_mode:
if insert_mode():
return "I"
elif replace_mode():
return "o"
else:
return ">"
return "^"

0 comments on commit afd245e

Please sign in to comment.