Permalink
Browse files

UPDATE: v0.1.1 view image from selected text

  • Loading branch information...
1 parent 9198cd7 commit 93b7cef8b6251aa9985d88c5f2f2751a5059ffd4 @rmaksim committed Jan 26, 2012
Showing with 13 additions and 18 deletions.
  1. +0 −3 Default (Windows).sublime-keymap
  2. +1 −1 README.md
  3. +12 −14 image_viewer.py
@@ -1,3 +0,0 @@
-[
- {"keys": ["super+i"], "command": "image_viewer"}
-]
View
@@ -1,6 +1,6 @@
# Image-Viewer
-**v0.1.0**
+**v0.1.1**
---
## View image from CSS declaration, HTML <img> tag, and may be from something else :)
View
@@ -1,5 +1,5 @@
'''
-Image-Viewer v0.1.0
+Image-Viewer v0.1.1
[
{"keys": ["super+i"], "command": "image_viewer"}
@@ -44,27 +44,25 @@ def is_image(file_name):
self.view_image(file_name)
else:
- cur_pos = view.sel()[0].a
- scope_reg = view.extract_scope(cur_pos)
+ for reg in self.view.sel():
- file_string = view.substr(scope_reg)
- with_quotes = re.match('^[\"\']{1}(.*)[\"\']{1}$', file_string)
- file_string = with_quotes.group(1) if with_quotes else file_string
+ scope_reg = view.extract_scope(reg.a) if reg.a == reg.b else reg
+ file_string = view.substr(scope_reg)
+ with_quotes = re.match('^[\"\']{1}(.*)[\"\']{1}$', file_string)
+ file_string = with_quotes.group(1) if with_quotes else file_string
- if is_image(file_string):
- dir_name = re.match('(.*)(\/.*)$', view.file_name())
- dir_name = dir_name.group(1) + "/" if dir_name else ""
- full_name = dir_name + file_string
- self.view_image(dir_name, file_string)
+ if is_image(file_string):
+ dir_name = os.path.dirname(view.file_name())
+ self.view_image(dir_name, file_string)
- else:
- sublime.error_message("Image-Viewer\n\nERROR: Image type is not recognized:\n\n" + file_string)
+ else:
+ sublime.error_message("Image-Viewer\n\nERROR: Image type is not recognized:\n\n" + file_string)
def view_image(self, dir_name, file_name = ""):
'''View image with default OS viewer'''
- full_name = dir_name + file_name
+ full_name = dir_name + "/" + file_name
if (os.path.isfile(full_name)):
desktop.open(full_name)

0 comments on commit 93b7cef

Please sign in to comment.