文件
mynode/packages/editor/CodeMirror/utils/clampSelectionToDocument.test.ts
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

40 行
1.0 KiB
TypeScript

import { EditorSelection, Text } from '@codemirror/state';
import clampSelectionToDocument from './clampSelectionToDocument';
describe('clampSelectionToDocument', () => {
it('should clamp a selection to the document', () => {
const doc = Text.of(['Testing...']);
const end = 'Testing...'.length;
expect(clampSelectionToDocument(
EditorSelection.single(end + 1), doc,
)).toMatchObject({
main: { from: end, to: end },
});
// Should map multiple at once
expect(clampSelectionToDocument(
EditorSelection.create([
EditorSelection.range(-1, 0),
EditorSelection.cursor(1),
EditorSelection.cursor(100),
], 2), doc,
)).toMatchObject({
ranges: [
{ from: 0, to: 0 },
{ from: 1, to: 1 },
{ from: end, to: end },
],
mainIndex: 2,
});
});
it('should not change a selection within the document', () => {
const doc = Text.of(['Test']);
// Should return the exact same selection
const selection = EditorSelection.single('Te'.length);
expect(clampSelectionToDocument(selection, doc)).toBe(selection);
});
});