Skip to content

Commit

Permalink
Merge pull request #112 from lostways/windows-new-line-fix
Browse files Browse the repository at this point in the history
fixed windows style newlines in titles and note view
  • Loading branch information
Samuel Walladge authored Aug 15, 2021
2 parents 2351229 + 32e0cd7 commit 2eeee22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 6 additions & 1 deletion simplenote_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
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]*)')
note_newline_re = re.compile(r'\r?\n')

def generate_random_key():
"""Generate random 30 digit (15 byte) hex string.
Expand Down Expand Up @@ -46,6 +47,10 @@ def get_note_flags(note):
flags += ' '
return flags

def get_note_lines(note):
lines = note_newline_re.split(note.get('content', ''))
return lines

def get_note_title(note):
mo = note_title_re.match(note.get('content', ''))
if mo:
Expand Down
9 changes: 5 additions & 4 deletions simplenote_cli/view_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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'].split('\n'):
for l in utils.get_note_lines(self.note):
lines.append(
urwid.AttrMap(urwid.Text(l.replace('\t', ' ' * self.tabstop)),
'note_content',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 2eeee22

Please sign in to comment.