I’m not sure when it appeared, only that I received a bug recently on HexViewer plugin that brought this issue to my attention.
Interestingly, it is not always reproducible, but I was able to force it with this. Don’t have a newline at the end of the last line:
00000000: 2320 4120 636f 6d6d 656e 740d 0a23 206d 6f72 6520 636f 6d6d :# A comment..# more comm
00000018: 656e 740d 0a76 6172 203d 2022 7374 7269 6e67 2220 2320 636f :ent..var = "string" # co
00000030: 6d6d 656e 740d 0a :mment..
Using this sublime-syntax
file which (for this reproduction) I’ll place in Packages/User/test.sublime-syntax
:
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: Hex
file_extensions: ['hex']
scope: source.hex
contexts:
main:
- match: '^([a-fA-F\d]{8}\:)([\s]{2})'
captures:
1: keyword.address.hex
2: dump.buffer-start.hex
push:
- meta_scope: dump.hex
- match: '[\s]{2}(\:)'
captures:
0: dump.buffer-end.hex
1: keyword.ascii-start.hex
pop: true
- match: '[\da-fA-F]{1}'
captures:
0: raw.nibble.upper.hex
push:
- meta_scope: raw.byte.hex
- match: '[\da-fA-F]{1}'
captures:
0: raw.nibble.lower.hex
pop: true
- match: '[\w\W]'
scope: invalid.illegal.expected-nibble.hex
- match: '[\s]{1}'
scope: raw.punctuation.hex
- match: '[\w\W]{1}\s*'
scope: invalid.illegal.character.hex
- match: '^[\w\W]*$'
scope: invalid.malformed-line.hex
- match: '[\w\W]*$'
scope: comment.ascii.hex
Then I set the syntax:
>>> view = sublime.active_window().active_view()
>>> view.set_syntax('Packages/User/test.sublime-syntax')
This gives me a view that looks like this (notice the last comment mment...
, that will be our target):
So now we grab the scope extent:
>>> view.substr(view.extract_scope(270))
':mment..'
Notice it grabs the :
for some reason.
Now if I add a newline:
>>> view.substr(view.extract_scope(270))
'mment..\n'
Maybe I’m missing something, but this seems like a bug.