Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
280 changes: 173 additions & 107 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"printWidth": 170
},
"devDependencies": {
"@lvce-editor/eslint-config": "^18.5.0",
"eslint": "^10.8.1",
"@lvce-editor/eslint-config": "^18.14.2",
"eslint": "^10.11.0",
"knip": "^6.32.2",
"prettier": "^3.9.6",
"typescript": "^6.0.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/build/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { join } from 'node:path'
import { pathToFileURL } from 'node:url'
import { root } from './root.ts'

export const threshold = 543_000
export const threshold = 546_000

export const instantiations = 8000

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { getInlineDiffRows } from '../GetInlineDiffRows/GetInlineDiffRows.ts'
import { getScrollBarDom } from '../GetScrollBarDom/GetScrollBarDom.ts'
import { mergeClassNames } from '../MergeClassNames/MergeClassNames.ts'

const inlineDiffEditorClassName = mergeClassNames(ClassNames.Viewlet, ClassNames.DiffEditor, ClassNames.InlineDiffEditor)
const inlineDiffEditorContentClassName = mergeClassNames(ClassNames.DiffEditorContent, ClassNames.InlineDiffEditorContent)

export const getInlineDiffEditorVirtualDom = (
contentLeft: string,
contentRight: string,
Expand Down Expand Up @@ -44,14 +47,14 @@ export const getInlineDiffEditorVirtualDom = (
return [
{
childCount: (scrollBarActive ? 3 : 2) + (searchVisible ? 1 : 0),
className: mergeClassNames(ClassNames.Viewlet, ClassNames.DiffEditor, ClassNames.InlineDiffEditor),
className: inlineDiffEditorClassName,
onWheel: DomEventListenerFunctions.HandleWheel,
type: VirtualDomElements.Div,
},
...searchHeaderDom,
{
childCount: contentChildCount,
className: mergeClassNames(ClassNames.DiffEditorContent, ClassNames.InlineDiffEditorContent),
className: inlineDiffEditorContentClassName,
type: VirtualDomElements.Div,
},
...lineNumberDom,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ import { VisibleLineType, type VisibleLine } from '../VisibleLine/VisibleLine.ts

type LineNumberType = VisibleLine['type'] | InlineDiffRow['type']

const diffEditorLineNumberDeletionClassName = mergeClassNames(ClassNames.DiffEditorLineNumber, ClassNames.DiffEditorLineNumberDeletion)
const diffEditorLineNumberInsertionClassName = mergeClassNames(ClassNames.DiffEditorLineNumber, ClassNames.DiffEditorLineNumberInsertion)
const diffEditorLineNumberMetaClassName = mergeClassNames(ClassNames.DiffEditorLineNumber, ClassNames.DiffEditorLineNumberMeta)

export const getLineNumberClassName = (type: LineNumberType = VisibleLineType.Normal): string => {
if (type === VisibleLineType.Removed || type === InlineDiffRowType.Deletion) {
return mergeClassNames(ClassNames.DiffEditorLineNumber, ClassNames.DiffEditorLineNumberDeletion)
return diffEditorLineNumberDeletionClassName
}
if (type === VisibleLineType.Added || type === InlineDiffRowType.Insertion) {
return mergeClassNames(ClassNames.DiffEditorLineNumber, ClassNames.DiffEditorLineNumberInsertion)
return diffEditorLineNumberInsertionClassName
}
if (type === InlineDiffRowType.GitButtons || type === InlineDiffRowType.IncomingChange) {
return mergeClassNames(ClassNames.DiffEditorLineNumber, ClassNames.DiffEditorLineNumberMeta)
return diffEditorLineNumberMetaClassName
}
return ClassNames.DiffEditorLineNumber
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { mergeClassNames } from '../../MergeClassNames/MergeClassNames.ts'
import { getRowClassName } from '../GetRowClassName/GetRowClassName.ts'
import { getTokenDom } from '../GetTokenDom/GetTokenDom.ts'

const lineMissingClassName = mergeClassNames(ClassNames.EditorRow, ClassNames.DiffEditorLineMissing)

export const getLineDom = (line: VisibleLine): readonly VirtualDomNode[] => {
const children = line.tokens.length === 0 ? [text('')] : line.tokens.flatMap(getTokenDom)
const childCount = line.tokens.length === 0 ? 1 : line.tokens.length
const className = line.lineNumber === -1 ? mergeClassNames(ClassNames.EditorRow, ClassNames.DiffEditorLineMissing) : getRowClassName(line.type)
const className = line.lineNumber === -1 ? lineMissingClassName : getRowClassName(line.type)
return [
{
childCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ const getLabel = (showWhitespace: boolean): string => {
return showWhitespace ? DiffStrings.hideWhitespace() : DiffStrings.showWhitespace()
}

const activeWhitespaceToggleClassName = mergeClassNames(ClassNames.DiffEditorWhitespaceToggle, ClassNames.DiffEditorWhitespaceToggleActive)

export const getWhitespaceToggleDom = (showWhitespace: boolean): readonly VirtualDomNode[] => {
const label = getLabel(showWhitespace)
const className = showWhitespace
? mergeClassNames(ClassNames.DiffEditorWhitespaceToggle, ClassNames.DiffEditorWhitespaceToggleActive)
: ClassNames.DiffEditorWhitespaceToggle
const className = showWhitespace ? activeWhitespaceToggleClassName : ClassNames.DiffEditorWhitespaceToggle
return [
{
childCount: 1,
Expand Down
3 changes: 2 additions & 1 deletion packages/e2e/src/diff.edit-right-side.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ export const test: Test = async ({ Command, DiffView, expect, FileSystem, Locato
await DiffView.open(`${tmpDir}/before.txt`, `${tmpDir}/after.txt`)

const afterRows = Locator('.DiffEditorContentRight .DiffEditorRows')
const afterRow = afterRows.locator('.EditorRow').first()
const input = Locator('.DiffEditorInput')

await expect(input).toHaveCount(1)
await Command.execute('DiffView.handleInput', 'gamma ')

await expect(input).toHaveValue('gamma ')
await expect(afterRows).toHaveText('gamma beta')
await expect(afterRows.locator('.EditorRow').first()).toHaveClass('EditorRow Insertion')
await expect(afterRow).toHaveClass('EditorRow Insertion')
}
6 changes: 4 additions & 2 deletions packages/e2e/src/diff.empty-after-pane-isolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ export const test: Test = async ({ DiffView, expect, FileSystem, Locator, Worksp
const beforePane = Locator('.DiffEditorContentLeft .DiffEditorRows')
const afterPane = Locator('.DiffEditorContentRight .DiffEditorRows')
const afterRows = Locator('.DiffEditorContentRight .DiffEditorRows')
const deletionRow = beforePane.locator('..EditorRow.Deletion')
const insertionRow = afterPane.locator('.DiffRow.Insertion')

await expect(beforePane.locator('..EditorRow.Deletion')).toHaveCount(1)
await expect(deletionRow).toHaveCount(1)
await expect(afterRows).toHaveText('')
await expect(afterPane.locator('.DiffRow.Insertion')).toHaveCount(0)
await expect(insertionRow).toHaveCount(0)
}
6 changes: 4 additions & 2 deletions packages/e2e/src/diff.empty-before-pane-isolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ export const test: Test = async ({ DiffView, expect, FileSystem, Locator, Worksp
const beforePane = Locator('.DiffEditorContentLeft .DiffEditorRows')
const afterPane = Locator('.DiffEditorContentRight .DiffEditorRows')
const beforeRows = Locator('.DiffEditorContentLeft .DiffEditorRows')
const deletionRow = beforePane.locator('..EditorRow.Deletion')
const insertionRow = afterPane.locator('.DiffRow.Insertion')

await expect(beforeRows).toHaveText('')
await expect(beforePane.locator('..EditorRow.Deletion')).toHaveCount(0)
await expect(afterPane.locator('.DiffRow.Insertion')).toHaveCount(1)
await expect(deletionRow).toHaveCount(0)
await expect(insertionRow).toHaveCount(1)
}
6 changes: 4 additions & 2 deletions packages/e2e/src/diff.rust-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ export const test: Test = async ({ DiffView, expect, FileSystem, Locator, Worksp

const beforePane = Locator('.DiffEditorContentLeft .DiffEditorRows')
const afterPane = Locator('.DiffEditorContentRight .DiffEditorRows')
const beforeKeywords = beforePane.locator('.Token.Keyword')
const afterKeywords = afterPane.locator('.Token.Keyword')

await expect(beforePane).toContainText('pub fn greet() {')
await expect(beforePane).toContainText('let message = "hello";')
await expect(afterPane).toContainText('pub fn greet() {')
await expect(afterPane).toContainText('let message = "hello, world";')
await expect(beforePane.locator('.Token.Keyword')).toHaveCount(3)
await expect(afterPane.locator('.Token.Keyword')).toHaveCount(3)
await expect(beforeKeywords).toHaveCount(3)
await expect(afterKeywords).toHaveCount(3)
}
3 changes: 2 additions & 1 deletion packages/e2e/src/diff.syntax-highlighting-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ export const test: Test = async ({ DiffView, expect, FileSystem, Locator, Worksp

const beforePane = Locator('.DiffEditorContentLeft .DiffEditorRows')
const afterPane = Locator('.DiffEditorContentRight .DiffEditorRows')
const beforeTagNames = beforePane.locator('.Token.TagName')

await expect(beforePane).toContainText('<html lang="en">')
await expect(afterPane).toContainText('<html lang="en">')
await expect(beforePane).toContainText('<h1>Left</h1>')
await expect(afterPane).toContainText('<h1>Right</h1>')
await expect(beforePane.locator('.Token.TagName')).toHaveCount(9)
await expect(beforeTagNames).toHaveCount(9)
}
6 changes: 4 additions & 2 deletions packages/e2e/src/diff.syntax-highlighting-java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ export const test: Test = async ({ DiffView, expect, FileSystem, Locator, Worksp

const beforePane = Locator('.DiffEditorContentLeft .DiffEditorRows')
const afterPane = Locator('.DiffEditorContentRight .DiffEditorRows')
const beforeKeywords = beforePane.locator('.Token.Keyword')
const afterKeywords = afterPane.locator('.Token.Keyword')

await expect(beforePane).toContainText('int count = 1;')
await expect(afterPane).toContainText('int count = 2;')
await expect(beforePane).toContainText('return;')
await expect(afterPane).toContainText('return;')
await expect(beforePane.locator('.Token.Keyword')).toHaveCount(5)
await expect(afterPane.locator('.Token.Keyword')).toHaveCount(5)
await expect(beforeKeywords).toHaveCount(5)
await expect(afterKeywords).toHaveCount(5)
}
18 changes: 12 additions & 6 deletions packages/e2e/src/diff.syntax-highlighting-tsx-react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,23 @@ export function Card(${openBrace} title, description }: CardProps): ReactNode {

const beforePane = Locator('.DiffEditorContentLeft .DiffEditorRows')
const afterPane = Locator('.DiffEditorContentRight .DiffEditorRows')
const beforeKeywordImports = beforePane.locator('.Token.KeywordImport')
const afterKeywordImports = afterPane.locator('.Token.KeywordImport')
const beforeKeywordFunctions = beforePane.locator('.Token.KeywordFunction')
const afterKeywordFunctions = afterPane.locator('.Token.KeywordFunction')
const beforeStrings = beforePane.locator('.Token.String')
const afterStrings = afterPane.locator('.Token.String')

await expect(beforePane).toContainText('readonly subtitle: string')
await expect(afterPane).toContainText('readonly description: string')
await expect(beforePane).toContainText('className="card"')
await expect(afterPane).toContainText('className="card card--selected"')
await expect(beforePane).toContainText("{isOpen ? 'Collapse' : 'Expand'}")
await expect(afterPane).toContainText("{isOpen ? 'Collapse' : 'Open'}")
await expect(beforePane.locator('.Token.KeywordImport')).toHaveCount(3)
await expect(afterPane.locator('.Token.KeywordImport')).toHaveCount(3)
await expect(beforePane.locator('.Token.KeywordFunction')).toHaveCount(0)
await expect(afterPane.locator('.Token.KeywordFunction')).toHaveCount(0)
await expect(beforePane.locator('.Token.String')).toHaveCount(5)
await expect(afterPane.locator('.Token.String')).toHaveCount(5)
await expect(beforeKeywordImports).toHaveCount(3)
await expect(afterKeywordImports).toHaveCount(3)
await expect(beforeKeywordFunctions).toHaveCount(0)
await expect(afterKeywordFunctions).toHaveCount(0)
await expect(beforeStrings).toHaveCount(5)
await expect(afterStrings).toHaveCount(5)
}
16 changes: 1 addition & 15 deletions packages/e2e/src/viewlet.diff-editor-scrolling.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
import type { Test } from '@lvce-editor/test-with-playwright'

const waitFor = async (assertion: () => Promise<void>): Promise<void> => {
let lastError: unknown
for (let attempt = 0; attempt < 20; attempt++) {
try {
await assertion()
return
} catch (error) {
lastError = error
await new Promise((resolve) => setTimeout(resolve, 50))
}
}
throw lastError
}

const getLargeFileContent = (bottomLine: string): string => {
const lines: string[] = []
for (let index = 1; index <= 1800; index++) {
Expand Down Expand Up @@ -48,5 +34,5 @@ export const test: Test = async ({ DiffView, expect, FileSystem, Locator, Worksp
const line1800 = Locator('.DiffEditorContentLeft .DiffEditorLineNumber', {
hasText: '1800',
})
await waitFor(() => expect(line1800).toBeVisible())
await expect(line1800).toBeVisible()
}
20 changes: 2 additions & 18 deletions packages/e2e/src/viewlet.diff-editor-typing-at-cursor.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
import type { Test } from '@lvce-editor/test-with-playwright'

const waitFor = async (assertion: () => Promise<void>): Promise<void> => {
let lastError: unknown
for (let attempt = 0; attempt < 20; attempt++) {
try {
await assertion()
return
} catch (error) {
lastError = error
await new Promise((resolve) => setTimeout(resolve, 50))
}
}
throw lastError
}

export const name = 'viewlet.diff-editor-typing-at-cursor'
export const test: Test = async ({ DiffView, expect, FileSystem, Locator, Workspace }) => {
const tmpDir = await FileSystem.getTmpDir()
Expand All @@ -34,8 +20,6 @@ export const test: Test = async ({ DiffView, expect, FileSystem, Locator, Worksp
await input.type(' abc')

await expect(input).toHaveValue(' abc')
await waitFor(async () => {
await expect(afterRows).toHaveText('helloWorld abc')
await expect(cursor).toHaveCSS('left', '175px')
})
await expect(afterRows).toHaveText('helloWorld abc')
await expect(cursor).toHaveCSS('left', '175px')
}
Loading