Attempt to fix the weird bug where marking any but the first column of the line, then marking on another line causes nothing to be copied.
This commit is contained in:
parent
10bc181241
commit
56f403b0b9
@ -10,30 +10,68 @@ from fenrirscreenreader.utils import mark_utils
|
|||||||
class command():
|
class command():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def getDescription(self):
|
def getDescription(self):
|
||||||
return _('copies marked text to the currently selected clipboard')
|
return _('copies marked text to the currently selected clipboard')
|
||||||
|
|
||||||
|
def getTextFromScreen(self, startMark, endMark):
|
||||||
|
screenContent = self.env['screen']['newContentText']
|
||||||
|
screenLines = screenContent.split('\n')
|
||||||
|
|
||||||
|
startY = min(startMark['y'], len(screenLines) - 1)
|
||||||
|
endY = min(endMark['y'], len(screenLines) - 1)
|
||||||
|
|
||||||
|
# If marks are on the same line
|
||||||
|
if startY == endY:
|
||||||
|
line = screenLines[startY]
|
||||||
|
startX = min(startMark['x'], len(line))
|
||||||
|
endX = min(endMark['x'], len(line))
|
||||||
|
return line[startX:endX]
|
||||||
|
|
||||||
|
# Handle multi-line selection
|
||||||
|
result = []
|
||||||
|
|
||||||
|
# First line (from start mark to end of line)
|
||||||
|
firstLine = screenLines[startY]
|
||||||
|
startX = min(startMark['x'], len(firstLine))
|
||||||
|
result.append(firstLine[startX:])
|
||||||
|
|
||||||
|
# Middle lines (complete lines)
|
||||||
|
for lineNum in range(startY + 1, endY):
|
||||||
|
result.append(screenLines[lineNum])
|
||||||
|
|
||||||
|
# Last line (from start to end mark)
|
||||||
|
if endY > startY:
|
||||||
|
lastLine = screenLines[endY]
|
||||||
|
endX = min(endMark['x'], len(lastLine))
|
||||||
|
result.append(lastLine[:endX])
|
||||||
|
|
||||||
|
return '\n'.join(result)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if not self.env['commandBuffer']['Marks']['1']:
|
if not self.env['commandBuffer']['Marks']['1']:
|
||||||
self.env['runtime']['outputManager'].presentText(_("One or two marks are needed"), interrupt=True)
|
self.env['runtime']['outputManager'].presentText(_("One or two marks are needed"), interrupt=True)
|
||||||
return
|
return
|
||||||
if not self.env['commandBuffer']['Marks']['2']:
|
if not self.env['commandBuffer']['Marks']['2']:
|
||||||
self.env['runtime']['cursorManager'].setMark()
|
self.env['runtime']['cursorManager'].setMark()
|
||||||
|
|
||||||
# use the last first and the last setted mark as range
|
# use the last first and the last setted mark as range
|
||||||
startMark = self.env['commandBuffer']['Marks']['1'].copy()
|
startMark = self.env['commandBuffer']['Marks']['1'].copy()
|
||||||
endMark = self.env['commandBuffer']['Marks']['2'].copy()
|
endMark = self.env['commandBuffer']['Marks']['2'].copy()
|
||||||
|
|
||||||
marked = mark_utils.getTextBetweenMarks(startMark, endMark, self.env['screen']['newContentText'])
|
# Replace mark_utils.getTextBetweenMarks with our new method
|
||||||
|
marked = self.getTextFromScreen(startMark, endMark)
|
||||||
|
|
||||||
self.env['runtime']['memoryManager'].addValueToFirstIndex('clipboardHistory', marked)
|
self.env['runtime']['memoryManager'].addValueToFirstIndex('clipboardHistory', marked)
|
||||||
# reset marks
|
# reset marks
|
||||||
self.env['runtime']['cursorManager'].clearMarks()
|
self.env['runtime']['cursorManager'].clearMarks()
|
||||||
|
|
||||||
self.env['runtime']['outputManager'].presentText(marked, soundIcon='CopyToClipboard', interrupt=True)
|
self.env['runtime']['outputManager'].presentText(marked, soundIcon='CopyToClipboard', interrupt=True)
|
||||||
|
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user