From 3e8c40a35e6948240280d3a26fe315a150d65f2b Mon Sep 17 00:00:00 2001 From: lostways Date: Fri, 13 Aug 2021 17:39:30 -0700 Subject: [PATCH 1/3] fixed windows style newlines in titles and note view --- simplenote_cli/utils.py | 2 +- simplenote_cli/view_note.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/simplenote_cli/utils.py b/simplenote_cli/utils.py index 708f43b..cdffbe4 100644 --- a/simplenote_cli/utils.py +++ b/simplenote_cli/utils.py @@ -9,7 +9,7 @@ import datetime, random, re, time # first line with non-whitespace should be the title -note_title_re = re.compile('\s*(.*)\n?') +note_title_re = re.compile(r'\s*([^\r\n]*)') def generate_random_key(): """Generate random 30 digit (15 byte) hex string. diff --git a/simplenote_cli/view_note.py b/simplenote_cli/view_note.py index 6e9ece6..a456f07 100644 --- a/simplenote_cli/view_note.py +++ b/simplenote_cli/view_note.py @@ -30,13 +30,13 @@ def get_note_content_as_list(self): if not self.key: return lines if self.old_note: - for l in self.old_note['content'].split('\n'): + for l in self.old_note['content'].splitlines(): lines.append( urwid.AttrMap(urwid.Text(l.replace('\t', ' ' * self.tabstop)), 'note_content_old', 'note_content_old_focus')) else: - for l in self.note['content'].split('\n'): + for l in self.note['content'].splitlines(): lines.append( urwid.AttrMap(urwid.Text(l.replace('\t', ' ' * self.tabstop)), 'note_content', From e242d5e3b032cadd594992689cae2428664853cc Mon Sep 17 00:00:00 2001 From: lostways Date: Sat, 14 Aug 2021 14:34:09 -0700 Subject: [PATCH 2/3] split note content in a consistent way --- simplenote_cli/utils.py | 7 +++++++ simplenote_cli/view_note.py | 9 +++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/simplenote_cli/utils.py b/simplenote_cli/utils.py index cdffbe4..5eba6b0 100644 --- a/simplenote_cli/utils.py +++ b/simplenote_cli/utils.py @@ -10,6 +10,7 @@ # first line with non-whitespace should be the title note_title_re = re.compile(r'\s*([^\r\n]*)') +note_newline_re = re.compile(r'\r?\n') def generate_random_key(): """Generate random 30 digit (15 byte) hex string. @@ -46,6 +47,12 @@ def get_note_flags(note): flags += ' ' return flags +def get_note_lines(note, max_lines=0): + lines = note_newline_re.split( + note.get('content', ''), + max_lines) + return lines + def get_note_title(note): mo = note_title_re.match(note.get('content', '')) if mo: diff --git a/simplenote_cli/view_note.py b/simplenote_cli/view_note.py index a456f07..37d6fbd 100644 --- a/simplenote_cli/view_note.py +++ b/simplenote_cli/view_note.py @@ -30,13 +30,13 @@ def get_note_content_as_list(self): if not self.key: return lines if self.old_note: - for l in self.old_note['content'].splitlines(): + for l in utils.get_note_lines(self.old_note): lines.append( urwid.AttrMap(urwid.Text(l.replace('\t', ' ' * self.tabstop)), 'note_content_old', 'note_content_old_focus')) else: - for l in self.note['content'].splitlines(): + for l in utils.get_note_lines(self.note): lines.append( urwid.AttrMap(urwid.Text(l.replace('\t', ' ' * self.tabstop)), 'note_content', @@ -105,8 +105,9 @@ def search_note_view_prev(self, search_string=None, search_mode=None): self.search_note_range(note_range) def search_note_range(self, note_range): + note_lines = utils.get_note_lines(self.note) for line in note_range: - line_content = self.note['content'].split('\n')[line] + line_content = note_lines[line] if (self.is_match(self.search_string, line_content)): self.focus_position = line break @@ -198,7 +199,7 @@ def get_status_bar(self): 'status_bar') def copy_note_text(self): - line_content = self.note['content'].split('\n')[self.focus_position] + line_content = utils.get_note_lines(self.note)[self.focus_position] self.clipboard.copy(line_content) def keypress(self, size, key): From 32e0cd7c6da528ce7347e702f29b5241a5ba21f1 Mon Sep 17 00:00:00 2001 From: lostways Date: Sun, 15 Aug 2021 12:28:10 -0700 Subject: [PATCH 3/3] removed max_lines from get_note_lines --- simplenote_cli/utils.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/simplenote_cli/utils.py b/simplenote_cli/utils.py index 5eba6b0..f62cde3 100644 --- a/simplenote_cli/utils.py +++ b/simplenote_cli/utils.py @@ -47,10 +47,8 @@ def get_note_flags(note): flags += ' ' return flags -def get_note_lines(note, max_lines=0): - lines = note_newline_re.split( - note.get('content', ''), - max_lines) +def get_note_lines(note): + lines = note_newline_re.split(note.get('content', '')) return lines def get_note_title(note):