Skip to content

Commit

Permalink
reduce calls to _lex_and_parse since set_buffer_contents does this; d…
Browse files Browse the repository at this point in the history
…o not clear messages from node.set_buffer_contents; MAJOR - bugfix for node_id resolution
  • Loading branch information
nbeversl committed Jul 8, 2024
1 parent 5ab39d5 commit 76929bf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
7 changes: 3 additions & 4 deletions urtext/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ def _parse(self,
nested_levels[nested].append([last_position, position])
if nested <= 0:
contents = contents[:position] + contents[position + 1:]
self.set_buffer_contents(contents)
return self._lex_and_parse()
return self.set_buffer_contents(contents, clear_messages=False)

position += 1 #wrappers exist outside range
node = self.add_node(
Expand Down Expand Up @@ -214,8 +213,7 @@ def _parse(self,
syntax.node_closing_wrapper,
' ',
contents[position:]])
self.set_buffer_contents(contents)
return self._lex_and_parse()
return self.set_buffer_contents(contents)

for node in self.nodes:
node.filename = self.filename
Expand Down Expand Up @@ -275,6 +273,7 @@ def set_buffer_contents(self,
self.contents = new_contents
if clear_messages:
self.__clear_messages()
return
if re_parse:
self._lex_and_parse()

Expand Down
4 changes: 2 additions & 2 deletions urtext/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def _set_contents(self, new_contents, preserve_title=True):
"""

node_contents = self.strip_first_line_title(self.full_contents)
file_contents = self.file._get_contents()
file_contents = self.file._get_contents()
if preserve_title and self.first_line_title:
new_node_contents = ''.join([
' ',
Expand All @@ -303,7 +303,7 @@ def _set_contents(self, new_contents, preserve_title=True):
file_contents[:self.start_position],
new_contents,
file_contents[self.end_position:]])
self.file.set_buffer_contents(new_file_contents)
self.file.set_buffer_contents(new_file_contents, clear_messages=False)
# does not re-parse into project

def replace_range(self,
Expand Down
7 changes: 3 additions & 4 deletions urtext/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,13 @@ def _resolve_node_ids(self, buffer):
node.id = resolution['resolved_id']
changed_ids[node.id] = resolution['resolved_id']
allocated_ids.append(node.id)

# resolve duplicate titles within file/buffer
new_file_node_ids = [file_node.id for file_node in buffer.nodes]
nodes_to_resolve = [n for n in buffer.nodes if new_file_node_ids.count(n.id) > 1]
allocated_ids.extend([file_node.id for file_node in buffer.nodes])
for n in nodes_to_resolve:
unresolved_id = n.id
resolution = n.resolve_id(allocated_ids=allocated_ids)
if not resolution['resolved_id'] or n.id in changed_ids:
if not resolution['resolved_id'] or resolution['resolved_id'] in changed_ids:
message = {
'top_message' :''.join([
'Dropping duplicate node title "',
Expand All @@ -388,7 +387,7 @@ def _resolve_node_ids(self, buffer):
buffer.nodes.remove(n)
del n
continue
changed_ids[n.id] = resolution['resolved_id']
changed_ids[unresolved_id] = resolution['resolved_id']
n.id = resolution['resolved_id']

# resolve duplicate titles in project
Expand Down

0 comments on commit 76929bf

Please sign in to comment.