Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cell cut, insert new cell after Ctrl-R if last #76

Merged
merged 1 commit into from
Feb 21, 2024
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
48 changes: 35 additions & 13 deletions plugins/notebook_editor/txl_notebook_editor/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ async def observe_nb_changes(self):
if delete is not None:
self.cells[idx].remove()
del self.cells[idx]
if self.cell_i == len(self.cells):
self.cell_i -= 1
self.current_cell.select()
self.current_cell.focus()
elif self.cell_i == 0:
self.current_cell.select()
self.current_cell.focus()
insert = d.get("insert")
if insert is not None:
for c in insert:
Expand Down Expand Up @@ -206,12 +213,7 @@ async def on_key(self, event: Event) -> None:
elif event.key == Keys.Down:
if not self.edit_mode:
event.stop()
if self.cell_i < len(self.cells) - 1:
self.current_cell.unselect()
self.cell_i += 1
self.current_cell.select()
self.current_cell.focus()
self.scroll_to_widget(self.current_cell)
self.go_down()
elif event.key == Keys.ControlUp:
event.stop()
if self.cell_i > 0:
Expand Down Expand Up @@ -272,7 +274,8 @@ async def do_later():
elif event.character == "x":
event.stop()
self.cell_copy = str(self.current_cell.ycell)
del self.ynb.ycells[self.cell_i]
if len(self.cells) > 1:
del self.ynb.ycells[self.cell_i]
elif event.key == Keys.ControlV:
event.stop()
if self.cell_copy is not None:
Expand Down Expand Up @@ -314,13 +317,32 @@ async def do_later():
)
else:
await self.kernel.execute(self.current_cell.ycell)
if self.cell_i < len(self.cells) - 1:
self.current_cell.unselect()
self.cell_i += 1
self.current_cell.select()
self.current_cell.source.focus()
if self.cell_i == len(self.cells) - 1:
ycell = self.ynb.create_ycell(
{
"cell_type": "code",
"execution_count": None,
"source": "",
}
)
self.ynb.ycells.append(ycell)
async def will_go_down():
while self.cell_i == len(self.cells) - 1:
await asyncio.sleep(0)
self.go_down(edit_mode=True)
asyncio.create_task(will_go_down())

def go_down(self, edit_mode: bool = False) -> None:
if self.cell_i < len(self.cells) - 1:
self.current_cell.unselect()
self.cell_i += 1
self.current_cell.select()
if edit_mode:
self.edit_mode = True
self.scroll_to_widget(self.current_cell)
self.current_cell.source.focus()
else:
self.current_cell.focus()
self.scroll_to_widget(self.current_cell)

def on_click(self) -> None:
for cell_i, cell in enumerate(self.cells):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pre-install-commands = [
"pip install -e ./plugins/widgets",

'pip install "jupyterlab>=4"',
'pip install jupyter-collaboration >=2',
'pip install "jupyter-collaboration >=2"',
]

[tool.ruff.lint]
Expand Down
Loading