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

Insert final new line on save if insert_final_newline is true #432

Merged
merged 1 commit into from
Oct 20, 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
#.idea/
1 change: 0 additions & 1 deletion src/biscuit/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from .cli import run

run()

7 changes: 6 additions & 1 deletion src/biscuit/editor/text/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(
self.words: list[str] = []
self.lsp: bool = False
self.current_indent_level = 0
self.insert_final_newline = False

self.hover_after = None
self.last_hovered = None
Expand Down Expand Up @@ -849,7 +850,7 @@ def set_block_cursor(self, flag: bool) -> None:
def toggle_relative_numbering(self) -> None:
self.relative_line_numbers = not self.relative_line_numbers
self.master.on_change()

def get_cursor_pos(self):
return self.index(tk.INSERT)

Expand Down Expand Up @@ -1125,6 +1126,10 @@ def custom_get(self, start: str, end: str) -> str:
return content

def save_file(self, path=None):
if self.insert_final_newline:
if not self.get("end-2c", "end-1c").endswith("\n"):
self.add_newline()

if path:
try:
with open(path, "w") as fp:
Expand Down
Loading