Skip to content

Commit

Permalink
Fixed number sequence not generating sequence. Close #2
Browse files Browse the repository at this point in the history
  • Loading branch information
hktonylee committed Oct 4, 2016
1 parent 820d49b commit a71c13b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
15 changes: 6 additions & 9 deletions core/number.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import sys
import sublime
import sublime_plugin
from core import utils
Expand All @@ -9,7 +10,7 @@
class KingWonderfullyManipulateSelectionCommand(sublime_plugin.TextCommand):
def on_done(self, text):
settings.set_last_used_selection_predicate(text)
self.view.run_command('king_manipulate_selection', {'formula': text})
self.view.run_command('king_manipulate_number', {'formula': text})

def ask_formula(self):
self.view.window().show_input_panel("Please enter the predicate formula (you may use 'x' and 'i'):",
Expand All @@ -31,38 +32,34 @@ def run(self, edit, formula):
try:
calculator = Calculator(formula)
except Exception as e:
sublime.error_message('Fail to calculate. Please check the input function.')
sublime.error_message('Error detected in the formula. Please check and correct it.')
return

current_sel = view.sel()

i = 0

# if select_type == SELECT_TYPE_AUTO:
# select_type = utils.infer_select_type()

if select_type == SELECT_TYPE_AUTO:
for sel in current_sel:
for i, sel in enumerate(current_sel):
result = calculator.calculate(i=i, x=float(view.substr(sel)))
if isinstance(result, float) and float.is_integer(result):
result = int(result)
view.replace(edit, sel, str(result))

elif select_type == SELECT_TYPE_FLOAT:
for sel in current_sel:
for i, sel in enumerate(current_sel):
result = calculator.calculate(i=i, x=float(view.substr(sel)))
view.replace(edit, sel, str(float(result)))

elif select_type in (SELECT_TYPE_INT, SELECT_TYPE_INT_NEAREST):
for sel in current_sel:
for i, sel in enumerate(current_sel):
result = calculator.calculate(i=i, x=int(view.substr(sel)))
if select_type == SELECT_TYPE_INT_NEAREST:
view.replace(edit, sel, str(int(round(result))))
else:
view.replace(edit, sel, str(int(result)))

i += 1


class KingWonderfullyManipulateCommand(sublime_plugin.TextCommand):
def on_done(self, text):
Expand Down
17 changes: 0 additions & 17 deletions core/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,3 @@ def askInterlacedCount(self):
def run(self, edit):
self.askInterlacedCount()


class KingManipulateSelectionCommand(sublime_plugin.TextCommand):
def run(self, edit, formula):
view = self.view
calculator = Calculator(formula)
current_sel = view.sel()
all_regions = []

i = 0
for sel in current_sel:
result = calculator.calculate(i=i, x=float(view.substr(sel)))
if result:
all_regions.append(sel)
i += 1

current_sel.clear()
current_sel.add_all(all_regions)

0 comments on commit a71c13b

Please sign in to comment.