-
Notifications
You must be signed in to change notification settings - Fork 0
/
sublime_vergleich.py
694 lines (553 loc) · 23 KB
/
sublime_vergleich.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
import sublime, sublime_plugin
import difflib
import threading, time, re, ntpath
import re
from pprint import pprint
# List of open / active diffs
diffSessions = []
def getDiffSessionByView(view):
global diffSessions
for diff in diffSessions:
try:
if view.id() in [diff.leftView.id(), diff.rightView.id()]:
return diff
except:
continue
return None
def isDiffSessionView(view):
return getDiffSessionByView(view) != None
# Class that represents a diff session
class DiffSession:
# Konstruktor
def __init__(self, leftName, rightName, leftContent, rightContent):
# init
self.leftView, self.rightView = None, None
self.leftRegionBegins, self.rightRegionBegins = [], []
self.leftRegions, self.rightRegions = [], []
self.currentRegionIndex = -1
self.scrollDaemon = None
self.oldLayout = None
self.leftContent, self.rightContent = "", ""
self.leftResult, self.rightResult = "", ""
self.hunks = []
self.leftContent = leftContent
self.rightContent = rightContent
self.leftName = leftName
self.rightName = rightName
global diffSessions
diffSessions.append(self)
def diff(self):
self.leftResult, self.rightResult, self.hunks = doDiff(self.leftContent, self.rightContent)
def show(self):
self.setVerticalSplitLayout()
global diffSessions
diffNumber = len(diffSessions)
# create left view
self.leftView = sublime.active_window().new_file()
self.leftView.set_scratch(True)
self.leftView.settings().set('word_wrap', False)
self.leftView.run_command('fill_with_content', {'content': self.leftResult})
self.leftView.set_name("Left Diff: " + self.leftName)
# create right view
self.rightView = sublime.active_window().new_file()
self.rightView.set_scratch(True)
self.rightView.settings().set('word_wrap', False)
self.rightView.run_command('fill_with_content', {'content': self.rightResult})
self.rightView.set_name("Right Diff: " + self.rightName)
# move views to corresponding group
moveViewToLeft(self.leftView)
moveViewToRight(self.rightView)
# create diff regions
# icon = "dot"
icon = ""
leftRegions, rightRegions = [], []
leftLineRegions, rightLineRegions = [], []
leftRegionBegins, rightRegionBegins = [], []
for hunk in self.hunks:
# left view
lineBegin, lineEnd = hunk[0], hunk[1]
beginLeftPos = self.leftView.text_point(lineBegin, 0)
endLeftPos = self.leftView.text_point(lineEnd, 0)
endLineRegion = self.leftView.full_line(endLeftPos)
endLineContent = self.leftView.substr(endLineRegion)
endLeftPos += len(endLineContent)
leftRegion = sublime.Region(beginLeftPos, endLeftPos)
self.leftRegions.append(leftRegion)
self.leftRegionBegins.append(beginLeftPos)
# right view
lineBegin, lineEnd = hunk[0], hunk[1]
beginRightPos = self.rightView.text_point(lineBegin, 0)
endRightPos = self.rightView.text_point(lineEnd, 0)
endLineRegion = self.rightView.full_line(endRightPos)
endLineContent = self.rightView.substr(endLineRegion)
endRightPos += len(endLineContent)
rightRegion = sublime.Region(beginRightPos, endRightPos)
self.rightRegions.append(rightRegion)
self.rightRegionBegins.append(beginRightPos)
self.leftView.add_regions("VERGLEICH_REGIONS", self.leftRegions, "invalid.deprecated", icon, sublime.DRAW_NO_OUTLINE)
self.rightView.add_regions("VERGLEICH_REGIONS", self.rightRegions, "invalid.deprecated", icon, sublime.DRAW_NO_OUTLINE)
if len(self.leftRegionBegins) == 0:
sublime.error_message("Compared objects are identical")
else:
sublime.status_message(str(len(self.leftRegionBegins)) + " Differences detected")
# init ScrollDaemon
self.scrollDaemon = ScrollDaemon(self.leftView, self.rightView)
self.scrollDaemon.start()
def close(self):
global diffSessions
if self.leftView is not None:
sublime.active_window().focus_view(self.leftView)
sublime.active_window().run_command('close_file')
if self.rightView is not None:
sublime.active_window().focus_view(self.rightView)
sublime.active_window().run_command('close_file')
self.leftView, self.rightView = None, None
self.leftRegions, self.rightRegions = None, None
self.currentRegionIndex = -1
self.scrollDaemon.stop()
if self.oldLayout and len(diffSessions) < 2:
sublime.active_window().set_layout(self.oldLayout)
self.oldLayout = None
try:
diffSessions.remove(self)
except:
pass
def setVerticalSplitLayout(self):
# already enough windows.
if sublime.active_window().num_groups() > 1:
return
else:
# save current layout
self.oldLayout = sublime.active_window().layout()
# create split view
sublime.active_window().set_layout({
"cols": [0.0, 0.5, 1.0],
"rows": [0.0, 1.0],
"cells": [
[0, 0, 1, 1],
[1, 0, 2, 1]
]
})
def highlightCurrentDiff(self, index):
leftRegion = self.leftRegions[index]
rightRegion = self.rightRegions[index]
tmpLeftRegions = []
for i in range(len(self.leftRegions)):
if i != index:
tmpLeftRegions.append(self.leftRegions[i])
tmpRightRegions = []
for i in range(len(self.rightRegions)):
if i != index:
tmpRightRegions.append(self.rightRegions[i])
self.leftView.add_regions("VERGLEICH_REGIONS", tmpLeftRegions, "invalid.deprecated", "", sublime.DRAW_NO_OUTLINE)
self.rightView.add_regions("VERGLEICH_REGIONS", tmpRightRegions, "invalid.deprecated", "", sublime.DRAW_NO_OUTLINE)
self.leftView.add_regions("VERGLEICH_REGIONS_CURRENT", [leftRegion], "invalid.illegal", "", sublime.DRAW_NO_OUTLINE)
self.rightView.add_regions("VERGLEICH_REGIONS_CURRENT", [rightRegion], "invalid.illegal", "", sublime.DRAW_NO_OUTLINE)
class VergleichEventListener(sublime_plugin.EventListener):
def on_close(self, view):
if isDiffSessionView(view):
diffSession = getDiffSessionByView(view)
if None in [diffSession.scrollDaemon, diffSession.leftView, diffSession.rightView]:
return
try:
if view.id() == diffSession.leftView.id():
diffSession.leftView = None
diffSession.close()
except:
pass
try:
if view.id() == diffSession.rightView.id():
diffSession.rightView = None
diffSession.close()
except:
pass
class ScrollDaemon(threading.Thread):
leftView, rightView = None, None
lastLeftViewportPosition, lastRightViewportPosition = (0,0), (0,0)
waitInMilliseconds = 10.0 / 1000.0
def __init__(self, leftView, rightView):
threading.Thread.__init__(self)
self.leftView = leftView
self.rightView = rightView
def run(self):
while True:
# one of the windows was closed, stop
if self.leftView is None or self.rightView is None:
return
# handle exception when a view is closed, then
# viewport_position will throw an error because
# the view doesn exist anymore.
try:
leftViewportPosition = self.leftView.viewport_position()
rightViewportPosition = self.rightView.viewport_position()
if self.lastLeftViewportPosition != leftViewportPosition:
self.rightView.set_viewport_position(self.leftView.viewport_position(), False)
self.lastLeftViewportPosition = leftViewportPosition
self.lastRightViewportPosition = leftViewportPosition
elif self.lastRightViewportPosition != rightViewportPosition:
self.leftView.set_viewport_position(self.rightView.viewport_position(), False)
self.lastLeftViewportPosition = rightViewportPosition
self.lastRightViewportPosition = rightViewportPosition
except:
return
time.sleep(self.waitInMilliseconds)
def stop(self):
self.leftView = None
self.rightView = None
class GotoNextDifferenceCommand(sublime_plugin.TextCommand):
def run(self, edit):
if isDiffSessionView(self.view):
diffSession = getDiffSessionByView(self.view)
if len(diffSession.leftRegions) == 0:
sublime.status_message("No difference to go to")
return
if diffSession.currentRegionIndex == -1:
diffSession.currentRegionIndex = 0
else:
diffSession.currentRegionIndex = (diffSession.currentRegionIndex+1) % len(diffSession.leftRegions)
diffSession.highlightCurrentDiff(diffSession.currentRegionIndex)
if (sublime.active_window().active_view().id() == diffSession.leftView.id() or
sublime.active_window().active_view().id() == diffSession.rightView.id()):
sublime.status_message("Difference " + str(diffSession.currentRegionIndex+1) + "/" + str(len(diffSession.leftRegions)))
diffSession.leftView.show(diffSession.leftRegionBegins[diffSession.currentRegionIndex], True)
class GotoPrevDifferenceCommand(sublime_plugin.TextCommand):
def run(self, edit):
if isDiffSessionView(self.view):
diffSession = getDiffSessionByView(self.view)
if len(diffSession.leftRegions) == 0:
sublime.status_message("No difference to go to")
return
if diffSession.currentRegionIndex == -1:
diffSession.currentRegionIndex = len(diffSession.leftRegionBegins)-1
else:
diffSession.currentRegionIndex = (diffSession.currentRegionIndex-1) % len(diffSession.leftRegions)
diffSession.highlightCurrentDiff(diffSession.currentRegionIndex)
if (sublime.active_window().active_view().id() == diffSession.leftView.id() or
sublime.active_window().active_view().id() == diffSession.rightView.id()):
sublime.status_message("Difference " + str(diffSession.currentRegionIndex+1) + "/" + str(len(diffSession.leftRegions)))
diffSession.leftView.show(diffSession.leftRegionBegins[diffSession.currentRegionIndex], True)
# Dummy command to fill new views
class FillWithContentCommand(sublime_plugin.TextCommand):
def run(self, edit, content):
self.view.insert(edit,0,content)
def doDiff(view1Content, view2Content):
# append new line to contents if they don't end with it so that they end both with a
# new line
if not view1Content.endswith("\n"): view1Content += "\n"
if not view2Content.endswith("\n"): view2Content += "\n"
# create arrays of every view content,
# needed for the diff and for further processing
# and alignment
view1ContentList = view1Content.splitlines(True)
view2ContentList = view2Content.splitlines(True)
# Do a diff in unified format
diffResult = list(difflib.unified_diff(view1ContentList, view2ContentList))
# for debug
# pprint(diffResult)
# Begin to analyze the diff at line 2,
currentLineIndex = 2
# contents for the comparision contents
leftDiffContent, rightDiffContent = "", ""
# count how many lines are in every diff content
leftDiffCount, rightDiffCount = 0, 0
relativeLeftLine, relativeRightLine = 0, 0
currentDiffHunkBegin = -1
diffHunks = []
currentLine = None
minusCount, plusCount = 0, 0
while currentLineIndex < len(diffResult):
# get current line including uniform diff annotation
currentLine = diffResult[currentLineIndex]
# get current line content without
# uniform diff annotation.
currentLineContent = currentLine[1:]
if currentLine.startswith(" "):
# fill up the side with new lines in which
# lines are missing.
if(minusCount > plusCount):
for i in range(plusCount, minusCount):
rightDiffContent += "\n"
rightDiffCount+=1
elif(plusCount > minusCount):
for i in range(minusCount, plusCount):
leftDiffContent += "\n"
leftDiffCount+=1
if currentDiffHunkBegin != -1:
diffHunks.append((currentDiffHunkBegin, leftDiffCount-1))
currentDiffHunkBegin = -1
# reset counters
minusCount = 0
plusCount = 0
# Add line to both sides
leftDiffContent += currentLineContent
rightDiffContent += currentLineContent
relativeLeftLine += 1
relativeRightLine += 1
leftDiffCount += 1
rightDiffCount += 1
elif currentLine.startswith("-"):
# hunk
if currentDiffHunkBegin == -1:
currentDiffHunkBegin = leftDiffCount
# If the side changes, fill not present lines
# in the right side on the left side with new lines
if plusCount > 0:
for i in range(0, plusCount-1):
leftDiffContent += "\n"
leftDiffCount += 1
plusCount = 0
else:
minusCount+=1
leftDiffContent += currentLineContent
leftDiffCount += 1
relativeLeftLine+=1
elif currentLine.startswith("+"):
# hunk
if currentDiffHunkBegin == -1:
currentDiffHunkBegin = leftDiffCount
# If the side changes, fill not present lines
# in on the right side with new lines
if minusCount > 0:
for i in range(0, minusCount-1):
rightDiffContent += "\n"
rightDiffCount += 1
minusCount = 0
else:
plusCount += 1
rightDiffContent += currentLineContent
relativeRightLine += 1
rightDiffCount += 1
elif currentLine.startswith("@@"):
# TODO: short notation @@ line,line @@
# long notation
longNotationRegex = re.match('@@\s-(\d+),(\d+)\s\+(\d+),(\d+)\s@@', currentLine)
shortNotationRegex = re.match('@@\s-(\d+)\s\+(\d+)\s@@', currentLine)
shortNotationRegexLeft = re.match('@@\s-(\d+),(\d+)\s\+(\d+)\s@@', currentLine)
shortNotationRegexRight = re.match('@@\s-(\d+)\s\+(\d+),(\d+)\s@@', currentLine)
if longNotationRegex:
# read data for filling up matching content
diffRegLeftBeginLine = int(longNotationRegex.groups()[0]) - 1
diffRegLeftLength = int(longNotationRegex.groups()[1])
diffRegRightBeginLine = int(longNotationRegex.groups()[2]) - 1
diffRegRightLength = int(longNotationRegex.groups()[3])
elif shortNotationRegex:
# read data for filling up matching content
diffRegLeftBeginLine = int(shortNotationRegex.groups()[0]) - 1
diffRegLeftLength = 1
diffRegRightBeginLine = int(shortNotationRegex.groups()[1]) - 1
diffRegRightLength = 1
elif shortNotationRegexLeft:
diffRegLeftBeginLine = int(shortNotationRegexLeft.groups()[0]) - 1
diffRegLeftLength = int(shortNotationRegexLeft.groups()[1])
diffRegRightBeginLine = int(shortNotationRegexLeft.groups()[2]) - 1
diffRegRightLength = 1
elif shortNotationRegexRight:
diffRegLeftBeginLine = int(shortNotationRegexRight.groups()[0]) - 1
diffRegLeftLength = 1
diffRegRightBeginLine = int(shortNotationRegexRight.groups()[1]) - 1
diffRegRightLength = int(shortNotationRegexRight.groups()[2])
if shortNotationRegex or longNotationRegex or shortNotationRegexLeft or shortNotationRegexRight:
# fill up left diffContent
for i in range(relativeLeftLine, diffRegLeftBeginLine):
leftDiffContent += view1ContentList[i]
leftDiffCount += 1
relativeLeftLine = diffRegLeftBeginLine
# fill up right diffContent
for i in range(relativeRightLine, diffRegRightBeginLine):
rightDiffContent += view2ContentList[i]
rightDiffCount += 1
relativeRightLine = diffRegRightBeginLine
if currentDiffHunkBegin != -1:
diffHunks.append((currentDiffHunkBegin, leftDiffCount-1))
currentDiffHunkBegin = -1
currentLineIndex+=1
# do last fill up with new lines
# fill up with new lines the other side where no content was
if(minusCount > plusCount):
for i in range(plusCount, minusCount):
rightDiffContent += "\n"
rightDiffCount += 1
elif(plusCount > minusCount):
for i in range(minusCount, plusCount):
leftDiffContent += "\n"
leftDiffCount += 1
if currentDiffHunkBegin != -1:
diffHunks.append((currentDiffHunkBegin, leftDiffCount-1))
currentDiffHunkBegin = -1
# is there still content left?
if(relativeLeftLine < len(view1ContentList)):
for i in range(relativeLeftLine, len(view1ContentList)):
leftDiffContent += view1ContentList[i]
leftDiffCount += 1
if(relativeRightLine < len(view2ContentList)):
for i in range(relativeRightLine, len(view2ContentList)):
rightDiffContent += view2ContentList[i]
rightDiffCount += 1
minusCount = 0
plusCount = 0
yield leftDiffContent
yield rightDiffContent
yield diffHunks
def moveViewToLeft(view):
# Move left view to left group
sublime.active_window().focus_group(0)
sublime.active_window().set_view_index(view, sublime.active_window().active_group(), 0)
sublime.active_window().focus_view(view)
def moveViewToRight(view):
# Move right view to right group
sublime.active_window().focus_group(1)
sublime.active_window().set_view_index(view, sublime.active_window().active_group(), 0)
sublime.active_window().focus_view(view)
class CompareToClipboardCommand(sublime_plugin.TextCommand):
def run(self, edit):
# get selectioncontent
selectionContent = ""
selections = self.view.sel()
for sel in selections:
selectionContent += self.view.substr(sel)
if not selectionContent.endswith("\n"):
selectionContent += "\n"
if(selectionContent != ""):
viewContent = selectionContent
# todo: fetch appropriate names
leftName = "(Selection)"
else:
viewContent = self.view.substr(sublime.Region(0,self.view.size()))
# todo: fetch appropriate names
leftName = ""
# clipboard
clipboardContent = sublime.get_clipboard()
if not clipboardContent.endswith("\n"):
clipboardContent += "\n"
rightName = "Clipboard"
leftResult, rightResult, hunks = doDiff(viewContent, clipboardContent)
showDiff(leftResult, rightResult, hunks)
diffSession = DiffSession(leftName, rightName, viewContent, clipboardContent)
diffSession.diff()
diffSession.show()
class CompareToViewCommand(sublime_plugin.TextCommand):
menuViewNames, menuViewFileNames, menuViewIds = [], [], []
view1, view2 = None, None
# Get a view by its id
def getViewById(self, id):
for view in self.view.window().views():
if view.id() == id:
return view
return None
def loadViews(self):
# Clear
self.menuViewNames = []
self.menuViewFileNames = []
self.menuViewIds = []
# get a list of the view for displaying
# it in the file selection menu
for view in self.view.window().views():
if(view.file_name() is None):
# view contains content that is not saved in a file
contentPreview = view.substr(sublime.Region(0, min(50, view.size())))
self.menuViewNames.append([contentPreview , 'untitled'])
else:
# get file informations of view
self.menuViewNames.append([ntpath.basename(view.file_name()), view.file_name()])
self.menuViewIds.append(view.id())
def run(self, edit):
# create list of open views
self.loadViews()
self.view1 = sublime.active_window().active_view()
self.view.window().show_quick_panel(self.menuViewNames, self.menuCallbackView)
def menuCallbackView(self, index):
if index == -1: return
viewName = self.menuViewNames[index]
viewId = self.menuViewIds[index]
self.view2 = self.getViewById(viewId)
view1Content = self.view1.substr(sublime.Region(0, self.view1.size()))
view2Content = self.view2.substr(sublime.Region(0, self.view2.size()))
selectionLeft = getSelectionString(self.view1)
selectionRight = getSelectionString(self.view2)
if(selectionLeft != ""): view1Content = selectionLeft
if(selectionRight != ""): view2Content = selectionRight
if not self.view1.file_name():
leftName = self.view1.substr(sublime.Region(0, min(30, self.view1.size())))
else:
leftName = ntpath.basename(self.view1.file_name())
if not self.view2.file_name():
rightName = self.view2.substr(sublime.Region(0, min(30, self.view2.size())))
else:
rightName = ntpath.basename(self.view2.file_name())
diffSession = DiffSession(leftName, rightName, view1Content, view2Content)
diffSession.diff()
diffSession.show()
class MergeRightCommand(sublime_plugin.TextCommand):
def run(self, edit):
if isDiffSessionView(self.view):
diffSession = getDiffSessionByView(self.view)
if diffSession.currentRegionIndex == -1:
# todo error
print("NOT AT ANY REGION YET, TO TO A DIFF!!")
return
leftRegion = diffSession.leftRegions[diffSession.currentRegionIndex]
leftRegionContent = diffSession.leftView.substr(leftRegion)
leftRegionLength = len(leftRegionContent)
rightRegion = diffSession.rightRegions[diffSession.currentRegionIndex]
rightRegionContent = diffSession.rightView.substr(rightRegion)
rightRegionLength = len(rightRegionContent)
lengthDifference = leftRegionLength - rightRegionLength
diffSession.rightView.sel().clear()
diffSession.rightView.sel().add(rightRegion)
diffSession.rightView.replace(edit, rightRegion, leftRegionContent)
diffSession.rightView.sel().clear()
# Adapt all of the regions
for i in range(len(diffSession.rightRegions)):
currentRegion = diffSession.rightRegions[i]
if i == diffSession.currentRegionIndex:
diffSession.rightRegions[i] = sublime.Region(currentRegion.begin(), currentRegion.end()+lengthDifference)
if i > diffSession.currentRegionIndex:
diffSession.rightRegions[i] = sublime.Region(currentRegion.begin()+lengthDifference, currentRegion.end()+lengthDifference)
else:
# do nothing, this are the regions before the change
pass
diffSession.rightView.add_regions("VERGLEICH_REGIONS", diffSession.rightRegions, "invalid.deprecated", "", sublime.DRAW_NO_OUTLINE)
diffSession.highlightCurrentDiff(diffSession.currentRegionIndex)
else:
# todo error no active session, please activate a diff session
return
class MergeLeftCommand(sublime_plugin.TextCommand):
def run(self, edit):
if isDiffSessionView(self.view):
diffSession = getDiffSessionByView(self.view)
if diffSession.currentRegionIndex == -1:
# todo error
print("NOT AT ANY REGION YET, TO TO A DIFF!!")
return
leftRegion = diffSession.leftRegions[diffSession.currentRegionIndex]
leftRegionContent = diffSession.leftView.substr(leftRegion)
leftRegionLength = len(leftRegionContent)
rightRegion = diffSession.rightRegions[diffSession.currentRegionIndex]
rightRegionContent = diffSession.rightView.substr(rightRegion)
rightRegionLength = len(rightRegionContent)
lengthDifference = rightRegionLength - leftRegionLength
diffSession.leftView.sel().clear()
diffSession.leftView.sel().add(leftRegion)
diffSession.leftView.replace(edit, leftRegion, rightRegionContent)
diffSession.leftView.sel().clear()
# Adapt all of the regions
for i in range(len(diffSession.leftRegions)):
currentRegion = diffSession.leftRegions[i]
if i == diffSession.currentRegionIndex:
diffSession.leftRegions[i] = sublime.Region(currentRegion.begin(), currentRegion.end()+lengthDifference)
if i > diffSession.currentRegionIndex:
diffSession.leftRegions[i] = sublime.Region(currentRegion.begin()+lengthDifference, currentRegion.end()+lengthDifference)
else:
# do nothing, this are the regions before the change
pass
diffSession.leftView.add_regions("VERGLEICH_REGIONS", diffSession.leftRegions, "invalid.deprecated", "", sublime.DRAW_NO_OUTLINE)
diffSession.highlightCurrentDiff(diffSession.currentRegionIndex)
else:
# todo error no active session, please activate a diff session
return
def getSelectionString(view):
lines = []
selections = view.sel()
for s in selections:
lines.append(view.substr(s))
return "\n".join(lines)