- Docs: Word-style dark page, phased fast open for long documents, fonts embedded in the DOCX, spellcheck toggle, hyperlink editing, and ~80 Word fidelity fixes (CJK/JP metrics, header/footer, tables, anchored pictures) - Sheets: hold formula recalculation while file data streams in, large-workbook scroll/load performance, combo charts, duplicate/unique conditional formatting by display text, RTL frozen-pane fix, workbooks whose ZIP entries carry a leading slash - Slides: MTX-compressed embedded font support, CJK/Latin face selection and PowerPoint script fallbacks, theme colors kept on paragraph defaults and bullets, more reliable AI edits with a layout audit after each batch - PDF: AI page ops, text block move/align, notes and markup editing, watermark and header/footer, form check boxes, metadata; the cloud Export as Word fallback is removed, conversion is always on-device - AI: Gemini tool schema translation, OpenCode Zen/Go providers, markdown tables and code blocks in chat, current date in the system prompt - Shell: Office-style ribbon collapse across all editors, native Windows ARM64 installer, BUILD_DIR override for packaging Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
130 lines
4.5 KiB
TypeScript
130 lines
4.5 KiB
TypeScript
/**
|
|
* Hyperlink viewing/editing (alpha ledger r164): the caret on an existing
|
|
* link must expose its range and address (the Ctrl+K dialog pre-fills and
|
|
* edits it), Remove Link strips the mark but keeps the text, and a
|
|
* tooltip-less link renders its target as the hover title without the
|
|
* fallback round-tripping into a stored tooltip.
|
|
*/
|
|
import { describe, expect, it } from 'vitest'
|
|
import { Editor, getMarkRange } from '@tiptap/core'
|
|
import { editorExtensions } from '../src/renderer/editor/extensions'
|
|
|
|
const makeEditor = (content?: object) =>
|
|
new Editor({
|
|
element: document.createElement('div'),
|
|
extensions: editorExtensions,
|
|
content: content ?? {
|
|
type: 'doc',
|
|
content: [
|
|
{
|
|
type: 'docParagraph',
|
|
content: [
|
|
{ type: 'text', text: 'visit ' },
|
|
{
|
|
type: 'text',
|
|
text: 'our site',
|
|
marks: [{ type: 'link', attrs: { href: 'https://old.example.com' } }],
|
|
},
|
|
{ type: 'text', text: ' today' },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
})
|
|
|
|
const linkRangeAtCaret = (editor: Editor) => {
|
|
const { $from } = editor.state.selection
|
|
return getMarkRange($from, editor.state.schema.marks.link!) ?? null
|
|
}
|
|
|
|
describe('link edit at caret (r164)', () => {
|
|
it('exposes the full link range and address from a caret inside it', () => {
|
|
const editor = makeEditor()
|
|
editor.commands.setTextSelection(10) // inside "our site"
|
|
const range = linkRangeAtCaret(editor)
|
|
expect(range).not.toBeNull()
|
|
expect(editor.state.doc.textBetween(range!.from, range!.to)).toBe('our site')
|
|
expect(editor.getAttributes('link').href).toBe('https://old.example.com')
|
|
editor.destroy()
|
|
})
|
|
|
|
it('address-only edit re-marks the run and keeps the text', () => {
|
|
const editor = makeEditor()
|
|
editor.commands.setTextSelection(10)
|
|
const range = linkRangeAtCaret(editor)!
|
|
editor
|
|
.chain()
|
|
.setTextSelection({ from: range.from, to: range.to })
|
|
.setMark('link', { href: 'https://new.example.com' })
|
|
.run()
|
|
editor.commands.setTextSelection(10)
|
|
expect(editor.getAttributes('link').href).toBe('https://new.example.com')
|
|
expect(editor.state.doc.textContent).toBe('visit our site today')
|
|
editor.destroy()
|
|
})
|
|
|
|
it('remove keeps the text and drops the mark', () => {
|
|
const editor = makeEditor()
|
|
editor.commands.setTextSelection(10)
|
|
const range = linkRangeAtCaret(editor)!
|
|
editor.chain().setTextSelection({ from: range.from, to: range.to }).unsetMark('link').run()
|
|
expect(editor.state.doc.textContent).toBe('visit our site today')
|
|
editor.commands.setTextSelection(10)
|
|
expect(editor.isActive('link')).toBe(false)
|
|
editor.destroy()
|
|
})
|
|
|
|
it('reads the address from the run at the trailing edge of a link', () => {
|
|
// inclusive:false drops the mark from $head.marks() at the trailing
|
|
// boundary — the range-based read must still see the address (bugbot)
|
|
const editor = makeEditor()
|
|
editor.commands.setTextSelection(15) // right after "our site"
|
|
const range = linkRangeAtCaret(editor)
|
|
expect(range).not.toBeNull()
|
|
const mark = editor.state.doc.nodeAt(range!.from)?.marks.find((m) => m.type.name === 'link')
|
|
expect(mark?.attrs.href).toBe('https://old.example.com')
|
|
editor.destroy()
|
|
})
|
|
|
|
it('renders the target as hover title without storing it as a tooltip', () => {
|
|
const editor = makeEditor()
|
|
expect(editor.getHTML()).toContain('title="https://old.example.com"')
|
|
// round-trip: the display-only fallback must not come back as a tooltip
|
|
const roundTripped = makeEditor()
|
|
roundTripped.commands.setContent(editor.getHTML())
|
|
let tooltip: unknown = 'unset'
|
|
roundTripped.state.doc.descendants((node) => {
|
|
const mark = node.marks.find((m) => m.type.name === 'link')
|
|
if (mark) tooltip = mark.attrs.tooltip
|
|
})
|
|
expect(tooltip).toBeNull()
|
|
editor.destroy()
|
|
roundTripped.destroy()
|
|
})
|
|
|
|
it('keeps a real stored tooltip as the hover title', () => {
|
|
const editor = makeEditor({
|
|
type: 'doc',
|
|
content: [
|
|
{
|
|
type: 'docParagraph',
|
|
content: [
|
|
{
|
|
type: 'text',
|
|
text: 'docs',
|
|
marks: [
|
|
{
|
|
type: 'link',
|
|
attrs: { href: 'https://a.example.com', tooltip: 'Open the docs' },
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
expect(editor.getHTML()).toContain('title="Open the docs"')
|
|
editor.destroy()
|
|
})
|
|
})
|