-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve findAlignedLines
#706
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,8 +48,8 @@ | |
|
||
import { valueIn, hasEntries, splitLines } from './util'; | ||
|
||
const PICKER_SYMBOL = '\u27ad'; | ||
const CONFLICT_MARKER = '\u26A0'; | ||
const PICKER_SYMBOL = '\u27ad\uFE0E'; | ||
const CONFLICT_MARKER = '\u26A0\uFE0E'; | ||
|
||
export enum DIFF_OP { | ||
DIFF_DELETE = -1, | ||
|
@@ -1179,17 +1179,26 @@ | |
* | ||
*/ | ||
function getMatchingEditLineLC(toMatch: Chunk, chunks: Chunk[]): number { | ||
let editLine = toMatch.baseFrom; | ||
console.log(toMatch, chunks) | ||
const editLine = toMatch.baseFrom; | ||
// Initialize with the last chunk in case we don't hit one of the | ||
// two escape conditions in the for loop. | ||
let previous: Chunk | undefined = chunks[chunks.length - 1]; | ||
for (let i = 0; i < chunks.length; ++i) { | ||
let chunk = chunks[i]; | ||
const chunk = chunks[i]; | ||
if (chunk.baseFrom === editLine) { | ||
// Chunk is part of the chunk list | ||
return chunk.remoteTo; | ||
} | ||
if (chunk.baseFrom > editLine) { | ||
// Remaining chunks are after the one we are interested | ||
previous = chunks[i - 1]; | ||
break; | ||
} | ||
} | ||
return toMatch.baseTo; | ||
// toMatch is not in chunks list, add lines delta from the last chunk | ||
console.log(previous, toMatch.baseTo + (previous ? (previous.remoteTo - previous.baseTo) : 0)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. debug log statement left behind |
||
return toMatch.baseTo + (previous ? (previous.remoteTo - previous.baseTo) : 0); | ||
} | ||
|
||
/** | ||
|
@@ -1211,7 +1220,7 @@ | |
let chunk = dv.lineChunks[i]; | ||
let lines = [chunk.baseTo, chunk.remoteTo]; | ||
|
||
for (let o of others) { | ||
for (const o of others) { | ||
lines.push(getMatchingEditLineLC(chunk, o.lineChunks)); | ||
} | ||
if ( | ||
|
@@ -1226,6 +1235,7 @@ | |
if (linesToAlign.length > 0) { | ||
let prev = linesToAlign[linesToAlign.length - 1]; | ||
let diff: number | null = lines[0] - prev[0]; | ||
// Skip this chunk if it does not required spacers | ||
for (let j = 1; j < lines.length; ++j) { | ||
if (diff !== lines[j] - prev[j]) { | ||
diff = null; | ||
|
@@ -1619,53 +1629,56 @@ | |
* Align the matching lines of the different editors | ||
*/ | ||
alignViews() { | ||
let lineHeight = this._showBase | ||
const lineHeight = this._showBase | ||
? this._base.cm.defaultLineHeight | ||
: this._diffViews[0].remoteEditorWidget.cm.defaultLineHeight; | ||
if (this._aligning) { | ||
return; | ||
} | ||
this._aligning = true; | ||
// Find matching lines | ||
let linesToAlign = findAlignedLines(this._diffViews); | ||
const linesToAlign = findAlignedLines(this._diffViews); | ||
console.log(linesToAlign) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. debug log statement left behind |
||
|
||
// Function modifying DOM to perform alignment: | ||
let editors: EditorView[] = [ | ||
const editors: EditorView[] = [ | ||
this.base.cm, | ||
...this._diffViews.map(dv => dv.remoteEditorWidget.cm), | ||
]; | ||
let builders: RangeSetBuilder<Decoration>[] = []; | ||
const builders: RangeSetBuilder<Decoration>[] = []; | ||
for (let i = 0; i < editors.length; i++) { | ||
builders.push(new RangeSetBuilder<Decoration>()); | ||
} | ||
|
||
let sumDeltas = new Array(editors.length).fill(0); | ||
let nLines = editors.map(editor => editor.state.doc.lines); | ||
const sumDeltas = new Array(editors.length).fill(0); | ||
const nLines = editors.map(editor => editor.state.doc.lines); | ||
|
||
for (let alignment_ of linesToAlign) { | ||
let alignment = this._showBase ? alignment_.slice(0, 3) : alignment_; | ||
let lastLine = Math.max(...alignment); | ||
let lineDeltas = alignment.map( | ||
for (const alignment_ of linesToAlign) { | ||
const alignment = this._showBase ? alignment_.slice(0, 3) : alignment_; | ||
const lastLine = Math.max(...alignment); | ||
const lineDeltas = alignment.map( | ||
(line, i) => lastLine - line - sumDeltas[i], | ||
); | ||
// If some paddings will be before the current line, it means all other editors | ||
// must add a padding. | ||
let minDelta = this._showBase | ||
const minDelta = this._showBase | ||
? Math.min(...lineDeltas) | ||
: Math.min(...lineDeltas.slice(1)); | ||
let correctedDeltas = lineDeltas.map(line => line - minDelta); | ||
const correctedDeltas = lineDeltas.map(line => line - minDelta); | ||
|
||
correctedDeltas.forEach((delta, i) => { | ||
// Don't compute anything for the base editor if it is hidden | ||
if (!this._showBase && i === 0) { | ||
return; | ||
} | ||
// Alignments are zero-based | ||
let line = alignment[i]; | ||
|
||
if (delta > 0 && line < nLines[i]) { | ||
sumDeltas[i] += delta; | ||
|
||
let offset = posToOffset(editors[i].state.doc, { | ||
// This method include the correction from zero-based lines to one-based lines | ||
const offset = posToOffset(editors[i].state.doc, { | ||
line, | ||
column: 0, | ||
}); | ||
|
@@ -1684,12 +1697,12 @@ | |
} | ||
|
||
// Padding at the last line of the editor | ||
let totalHeight = nLines.map((line, i) => line + sumDeltas[i]); | ||
let maxHeight = Math.max(...totalHeight); | ||
const totalHeight = nLines.map((line, i) => line + sumDeltas[i]); | ||
const maxHeight = Math.max(...totalHeight); | ||
totalHeight.slice(0, this._showBase ? 3 : 4).forEach((line, i) => { | ||
if (maxHeight > line) { | ||
let end = editors[i].state.doc.length; | ||
let delta = maxHeight - line; | ||
const end = editors[i].state.doc.length; | ||
const delta = maxHeight - line; | ||
sumDeltas[i] += delta; | ||
builders[i].add( | ||
end, | ||
|
@@ -1717,7 +1730,7 @@ | |
continue; | ||
} | ||
|
||
let decoSet: DecorationSet = builders[i].finish(); | ||
const decoSet: DecorationSet = builders[i].finish(); | ||
if ( | ||
!RangeSet.eq([decoSet], [editors[i].state.field(paddingWidgetField)]) | ||
) { | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test.describe('merge test5', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto('http://localhost:41000/merge'); | ||
await page.locator('#merge-local').fill('data/merge_test5/left.ipynb'); | ||
await page.locator('#merge-base').fill('data/merge_test5/center.ipynb'); | ||
await page.locator('#merge-remote').fill('data/merge_test5/right.ipynb'); | ||
await page.getByRole('button', { name: 'Merge files' }).click(); | ||
}); | ||
|
||
test('take a snapshot at opening', async ({ page }) => { | ||
await expect.soft(page.getByText('➭')).toHaveCount(16); | ||
expect.soft(await page.locator('#main').screenshot()).toMatchSnapshot(); | ||
}); | ||
}); |
Binary file added
BIN
+202 KB
...erge-test5.spec.ts-snapshots/merge-test5-take-a-snapshot-at-opening-1-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+120 KB
...erge-test5.spec.ts-snapshots/merge-test5-take-a-snapshot-at-opening-1-win32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log statement