
from xpcom import components
viewSvc = components.classes["@activestate.com/koViewService;1"]\
    .getService(components.interfaces.koIViewService)
view = viewSvc.currentView
view = view.queryInterface(components.interfaces.koIScintillaView)
sm = view.scimoz

# Make `start` the beginning position of the first selected line,
# and `end` the ending position of the last selected line.
if sm.anchor < sm.currentPos:
    start = sm.positionFromLine(sm.lineFromPosition(sm.anchor))
    end = sm.getLineEndPosition(sm.lineFromPosition(sm.currentPos))
else:
    start = sm.positionFromLine(sm.lineFromPosition(sm.currentPos))
    end = sm.getLineEndPosition(sm.lineFromPosition(sm.anchor))

lines = tuple(sm.getTextRange(start, end).splitlines())
# Cut one character from the left
lines = tuple(l[1:] for l in lines)

# Select part of document
sm.setSel(start, end)
# Replace selection content
text = '\n'.join(lines)
sm.replaceSel(text)
# Keep selection to allow to continue to apply this macro if use wants
sm.setSel(start, start+len(text))


from xpcom import components
viewSvc = components.classes["@activestate.com/koViewService;1"]\
    .getService(components.interfaces.koIViewService)
view = viewSvc.currentView
view = view.queryInterface(components.interfaces.koIScintillaView)
sm = view.scimoz

# Make `start` the beginning position of the first selected line,
# and `end` the ending position of the last selected line.
if sm.anchor < sm.currentPos:
    start = sm.positionFromLine(sm.lineFromPosition(sm.anchor))
    end = sm.getLineEndPosition(sm.lineFromPosition(sm.currentPos))
else:
    start = sm.positionFromLine(sm.lineFromPosition(sm.currentPos))
    end = sm.getLineEndPosition(sm.lineFromPosition(sm.anchor))

lines = tuple(sm.getTextRange(start, end).splitlines())
# Cut one character from the left
lines = tuple(l[1:] for l in lines)

# Select part of document
sm.setSel(start, end)
# Replace selection content
text = '\n'.join(lines)
sm.replaceSel(text)
# Keep selection to let user continue to apply this macro
sm.setSel(start, start+len(text.encode('utf-8')))

Correct selecting text by length when text is Unicode.
Correct selecting text by length when text is Unicode.

  
  from xpcom import components
  viewSvc = components.classes["@activestate.com/koViewService;1"]\
      .getService(components.interfaces.koIViewService)
  view = viewSvc.currentView
  view = view.queryInterface(components.interfaces.koIScintillaView)
  sm = view.scimoz
  
  # Make `start` the beginning position of the first selected line,
  # and `end` the ending position of the last selected line.
  if sm.anchor < sm.currentPos:
      start = sm.positionFromLine(sm.lineFromPosition(sm.anchor))
      end = sm.getLineEndPosition(sm.lineFromPosition(sm.currentPos))
  else:
      start = sm.positionFromLine(sm.lineFromPosition(sm.currentPos))
      end = sm.getLineEndPosition(sm.lineFromPosition(sm.anchor))
  
  lines = tuple(sm.getTextRange(start, end).splitlines())
  # Cut one character from the left
  lines = tuple(l[1:] for l in lines)
  
  # Select part of document
  sm.setSel(start, end)
  # Replace selection content
  text = '\n'.join(lines)
  sm.replaceSel(text)
- # Keep selection to allow to continue to apply this macro if use wants
+ # Keep selection to let user continue to apply this macro
- sm.setSel(start, start+len(text))
+ sm.setSel(start, start+len(text.encode('utf-8')))
  
Correct selecting text by length when text is Unicode.
## Code Before:

from xpcom import components
viewSvc = components.classes["@activestate.com/koViewService;1"]\
    .getService(components.interfaces.koIViewService)
view = viewSvc.currentView
view = view.queryInterface(components.interfaces.koIScintillaView)
sm = view.scimoz

# Make `start` the beginning position of the first selected line,
# and `end` the ending position of the last selected line.
if sm.anchor < sm.currentPos:
    start = sm.positionFromLine(sm.lineFromPosition(sm.anchor))
    end = sm.getLineEndPosition(sm.lineFromPosition(sm.currentPos))
else:
    start = sm.positionFromLine(sm.lineFromPosition(sm.currentPos))
    end = sm.getLineEndPosition(sm.lineFromPosition(sm.anchor))

lines = tuple(sm.getTextRange(start, end).splitlines())
# Cut one character from the left
lines = tuple(l[1:] for l in lines)

# Select part of document
sm.setSel(start, end)
# Replace selection content
text = '\n'.join(lines)
sm.replaceSel(text)
# Keep selection to allow to continue to apply this macro if use wants
sm.setSel(start, start+len(text))

## Instruction:
Correct selecting text by length when text is Unicode.
## Code After:

from xpcom import components
viewSvc = components.classes["@activestate.com/koViewService;1"]\
    .getService(components.interfaces.koIViewService)
view = viewSvc.currentView
view = view.queryInterface(components.interfaces.koIScintillaView)
sm = view.scimoz

# Make `start` the beginning position of the first selected line,
# and `end` the ending position of the last selected line.
if sm.anchor < sm.currentPos:
    start = sm.positionFromLine(sm.lineFromPosition(sm.anchor))
    end = sm.getLineEndPosition(sm.lineFromPosition(sm.currentPos))
else:
    start = sm.positionFromLine(sm.lineFromPosition(sm.currentPos))
    end = sm.getLineEndPosition(sm.lineFromPosition(sm.anchor))

lines = tuple(sm.getTextRange(start, end).splitlines())
# Cut one character from the left
lines = tuple(l[1:] for l in lines)

# Select part of document
sm.setSel(start, end)
# Replace selection content
text = '\n'.join(lines)
sm.replaceSel(text)
# Keep selection to let user continue to apply this macro
sm.setSel(start, start+len(text.encode('utf-8')))
