summaryrefslogtreecommitdiff
path: root/comments.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2016-02-17 01:10:00 +0100
committerAnthon van der Neut <anthon@mnt.org>2016-02-17 01:10:00 +0100
commit7ae833545063f1ddad8468f4dc92cc0240b4d97c (patch)
tree323328c4c49a0e24d3564042b3a8b15e7837a287 /comments.py
parentaf7395581fada1750f45855fb8420e0dd8d5ee19 (diff)
downloadruamel.yaml-7ae833545063f1ddad8468f4dc92cc0240b4d97c.tar.gz
- added CommentedSeq insert and pop with moving comments0.10.23
(issue brought up by Michael Sarahan)
Diffstat (limited to 'comments.py')
-rw-r--r--comments.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/comments.py b/comments.py
index f82e1c4..7cac4f6 100644
--- a/comments.py
+++ b/comments.py
@@ -261,6 +261,23 @@ class CommentedSeq(list, CommentedBase):
def _yaml_get_columnX(self, key):
return self.ca.items[key][0].start_mark.column
+ def insert(self, idx, val):
+ """the comments after the insertion have to move forward"""
+ list.insert(self, idx, val)
+ for list_index in sorted(self.ca.items, reverse=True):
+ if list_index < idx:
+ break
+ self.ca.items[list_index+1] = self.ca.items.pop(list_index)
+
+ def pop(self, idx):
+ res = list.pop(self, idx)
+ self.ca.items.pop(idx, None) # might not be there -> default value
+ for list_index in sorted(self.ca.items):
+ if list_index < idx:
+ continue
+ self.ca.items[list_index-1] = self.ca.items.pop(list_index)
+ return res
+
def _yaml_get_column(self, key):
column = None
sel_idx = None