Skip to content
Draft
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
3 changes: 3 additions & 0 deletions .github/workflows/canvas-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
env:
IOS_SIMULATOR_FAMILY: ipad
steps:
- name: Disable Spotlight indexing on the disposable audit runner
run: sudo mdutil -i off /
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -106,6 +108,7 @@ jobs:
-only-testing:OpenNotesUITests/NotebookInteractionUITests/testDrawingOverImageSurvivesUndoAndReload \
-only-testing:OpenNotesUITests/NotebookInteractionUITests/testInvalidNativePayloadShowsRecoveryWithoutOverwritingNote \
-only-testing:OpenNotesUITests/NotebookInteractionUITests/testPreferencesAndReturnToPen \
-only-testing:OpenNotesUITests/NotebookInteractionUITests/testLineSpacingSurvivesRelaunch \
-only-testing:OpenNotesUITests/NotebookInteractionUITests/testChoosePhotoCover \
-collect-test-diagnostics never
- name: Preserve interaction test evidence
Expand Down
7 changes: 4 additions & 3 deletions app/folder/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
listFolders,
renameFolder,
} from '../../src/services/foldersRepo';
import type { BackgroundType, FolderMetadata, NoteMetadata } from '../../src/types/note';
import type { BackgroundType, FolderMetadata, LineSpacing, NoteMetadata } from '../../src/types/note';

type Action =
| { kind: 'createNoteBackground' }
Expand Down Expand Up @@ -72,7 +72,7 @@ export default function FolderScreen() {
}, [refresh]),
);

const handleCreateNote = useCallback(async (backgroundType: BackgroundType, title: string) => {
const handleCreateNote = useCallback(async (backgroundType: BackgroundType, title: string, lineSpacing: LineSpacing) => {
if (!folder || creatingNoteRef.current) return;
creatingNoteRef.current = true;
setAction(null);
Expand All @@ -82,6 +82,7 @@ export default function FolderScreen() {
const meta = await createNote({
folderId: folder.id,
backgroundType,
lineSpacing,
title: title.trim() || undefined,
});
router.push(`/note/${meta.id}`);
Expand Down Expand Up @@ -185,7 +186,7 @@ export default function FolderScreen() {

<CreateNoteBackgroundSheet
visible={action?.kind === 'createNoteBackground'}
onPick={(type, title) => void handleCreateNote(type, title)}
onPick={(type, title, lineSpacing) => void handleCreateNote(type, title, lineSpacing)}
onClose={() => setAction(null)}
/>

Expand Down
7 changes: 4 additions & 3 deletions app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
listFolders,
renameFolder,
} from '../src/services/foldersRepo';
import type { BackgroundType, FolderMetadata, NoteMetadata } from '../src/types/note';
import type { BackgroundType, FolderMetadata, LineSpacing, NoteMetadata } from '../src/types/note';
import { t } from '../src/i18n';

type Action =
Expand Down Expand Up @@ -154,7 +154,7 @@ export default function LibraryScreen() {
[router],
);

const handleCreateNote = useCallback(async (backgroundType: BackgroundType, title: string) => {
const handleCreateNote = useCallback(async (backgroundType: BackgroundType, title: string, lineSpacing: LineSpacing) => {
if (creatingNoteRef.current) return;
creatingNoteRef.current = true;
setAction(null);
Expand All @@ -163,6 +163,7 @@ export default function LibraryScreen() {
const meta = await createNote({
folderId: libraryLayout === 'columns' && selection.kind === 'folder' ? selection.id : null,
backgroundType,
lineSpacing,
title: title.trim() || undefined,
});
openNote(meta.id);
Expand Down Expand Up @@ -387,7 +388,7 @@ export default function LibraryScreen() {

<CreateNoteBackgroundSheet
visible={action?.kind === 'createNoteBackground'}
onPick={(type, title) => void handleCreateNote(type, title)}
onPick={(type, title, lineSpacing) => void handleCreateNote(type, title, lineSpacing)}
onClose={() => setAction(null)}
/>

Expand Down
34 changes: 30 additions & 4 deletions app/note/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
readNoteBody,
renameNote,
saveNoteBody,
setNoteLineSpacing,
} from '../../src/services/notesRepo';
import { createEmptyNotebookData } from '../../src/services/noteBodyStorage';
import {
Expand All @@ -72,11 +73,12 @@ import { recordSuccessfulNoteSave } from '../../src/services/lifecycleService';
import { duplicateAssetPosition } from '../../src/utils/continuousAssets';
import { documentVisualLayers, imageAtContentPoint } from '../../src/utils/visualLayerOrder';
import { insertImagePosition } from '../../src/utils/insertImagePosition';
import { paperBackgroundType, resolveLineSpacing } from '../../src/utils/paperSpacing';
import { textBoxId, insertedElementId } from '../../src/utils/id';
import { spacing } from '../../src/theme/spacing';
import { t } from '../../src/i18n';
import { typography } from '../../src/theme/typography';
import type { NoteMetadata } from '../../src/types/note';
import type { LineSpacing, NoteMetadata } from '../../src/types/note';
import type { ToolDescriptor } from '../../src/utils/toolPalette';

const CONTENT_PADDING = 16;
Expand Down Expand Up @@ -160,6 +162,8 @@ export default function NoteScreen() {
const lastPenToolRef = useRef<'pen' | 'highlighter' | 'crayon' | 'calligraphy'>('pen');

const [metadata, setMetadata] = useState<NoteMetadata | null>(null);
const [lineSpacingBusy, setLineSpacingBusy] = useState(false);
const lineSpacingBusyRef = useRef(false);
const [enginePages, setEnginePages] = useState<NotebookPage[]>([]);
const enginePagesRef = useRef(enginePages);
const updateEnginePages = useCallback((pages: NotebookPage[]) => {
Expand Down Expand Up @@ -788,6 +792,23 @@ export default function NoteScreen() {
[id],
);

const handleLineSpacing = useCallback(async (value: LineSpacing) => {
if (!id || lineSpacingBusyRef.current) return;
lineSpacingBusyRef.current = true;
setLineSpacingBusy(true);
try {
const next = await setNoteLineSpacing(id, value);
if (!next) throw new Error('Note not found');
if (isMountedRef.current) setMetadata(next);
} catch (error) {
if (__DEV__) console.warn('[NoteScreen] line spacing update failed', error);
Alert.alert(t.editor.statusError, t.common.pleaseTryAgain);
} finally {
lineSpacingBusyRef.current = false;
if (isMountedRef.current) setLineSpacingBusy(false);
}
}, [id]);

const handleExport = useCallback(async () => {
if (!id || !canvasRef.current || isExporting) return;
setIsExporting(true);
Expand All @@ -810,6 +831,7 @@ export default function NoteScreen() {
const result = await exportNotebookAsPdf({
data: { ...canvasData, pages: mergedPages },
pdfBackgroundUri: metadata?.pdfUri ?? null,
backgroundType: paperBackgroundType(metadata?.backgroundType ?? 'plain', metadata?.lineSpacing),
filename,
});
if (!result.ok) {
Expand All @@ -830,6 +852,8 @@ export default function NoteScreen() {
isExporting,
mergeStoredPreviews,
metadata?.pdfUri,
metadata?.backgroundType,
metadata?.lineSpacing,
metadata?.title,
rememberPagePreviews,
]);
Expand Down Expand Up @@ -1039,7 +1063,7 @@ export default function NoteScreen() {
pageHeight={PAGE_HEIGHT}
toolState={toolState}
holdToShapeEnabled={holdToShape}
backgroundType={metadata?.backgroundType ?? 'plain'}
backgroundType={paperBackgroundType(metadata?.backgroundType ?? 'plain', metadata?.lineSpacing)}
pdfBackgroundBaseUri={metadata?.pdfUri ?? undefined}
fingerDrawingEnabled={fingerDrawingEnabled}
onContentTap={hasSelectableImages && !fingerDrawingEnabled && !['select', 'text', 'insert'].includes(toolState.toolType)
Expand Down Expand Up @@ -1098,7 +1122,7 @@ export default function NoteScreen() {
<PageSidebar
visible={isPageSidebarOpen}
pages={pagesForOverlay}
backgroundType={metadata?.backgroundType ?? 'plain'}
backgroundType={paperBackgroundType(metadata?.backgroundType ?? 'plain', metadata?.lineSpacing)}
pdfUri={metadata?.pdfUri}
currentPage={currentPageIndex}
topInset={headerHeight}
Expand Down Expand Up @@ -1128,7 +1152,9 @@ export default function NoteScreen() {
onClose={() => setToolPopover(null)}
/>

<PreferencesSheet visible={action?.kind === 'preferences'} onClose={() => setAction(null)} />
<PreferencesSheet visible={action?.kind === 'preferences'} onClose={() => setAction(null)}
noteLineSpacing={metadata?.backgroundType === 'lined' ? resolveLineSpacing(metadata.lineSpacing) : undefined}
onNoteLineSpacingChange={value => void handleLineSpacing(value)} lineSpacingBusy={lineSpacingBusy} />

<ItemActionsMenu
visible={action?.kind === 'insertImage'}
Expand Down
39 changes: 39 additions & 0 deletions ios/OpenNotesUITests/NotebookInteractionUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,45 @@ import XCTest
import UIKit

final class NotebookInteractionUITests: NotebookUITestCase {
func testLineSpacingSurvivesRelaunch() {
let app = XCUIApplication(bundleIdentifier: "com.builderpro.opennotes")
app.launchArguments = ["-AppleLanguages", "(en)", "-AppleLocale", "en_US"]
launchPrepared(app)
let dismiss = app.buttons["Not now"]
if dismiss.waitForExistence(timeout: 2) { dismiss.tap() }
tap(app, "library-create")
tap(app, "New Note")
tap(app, "paper-lined-narrow")
XCTAssertTrue(element(app, "ink-viewport").waitForExistence(timeout: 20))
tap(app, "editor-preferences")
XCTAssertTrue(element(app, "note-line-spacing-narrow").isSelected)
tap(app, "note-line-spacing-compact")
let selected = XCTNSPredicateExpectation(predicate: NSPredicate(format: "selected == true"),
object: element(app, "note-line-spacing-compact"))
XCTAssertEqual(XCTWaiter.wait(for: [selected], timeout: 10), .completed)
let slider = element(app, "line-spacing-slider")
XCTAssertTrue(slider.waitForExistence(timeout: 10))
let previous = String(describing: slider.value)
slider.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).press(forDuration: 0.05,
thenDragTo: slider.coordinate(withNormalizedOffset: CGVector(dx: 0.8, dy: 0.5)))
let custom = String(describing: slider.value)
XCTAssertNotEqual(previous, custom, "Dragging must change the custom line spacing")
let saved = XCTNSPredicateExpectation(predicate: NSPredicate(format: "enabled == true"), object: slider)
XCTAssertEqual(XCTWaiter.wait(for: [saved], timeout: 10), .completed)
tap(app, "Done")
tap(app, "Library")
let createdNote = app.descendants(matching: .any).matching(
NSPredicate(format: "identifier BEGINSWITH %@", "note-note-")).firstMatch
XCTAssertTrue(createdNote.waitForExistence(timeout: 20))
let createdNoteId = createdNote.identifier
app.terminate()
launchPrepared(app)
tap(app, createdNoteId)
XCTAssertTrue(element(app, "ink-viewport").waitForExistence(timeout: 20))
tap(app, "editor-preferences")
XCTAssertEqual(String(describing: element(app, "line-spacing-slider").value), custom)
}

func testMathNotesInvitationCanBeDismissedPermanently() {
let app = XCUIApplication(bundleIdentifier: "com.builderpro.opennotes")
app.launchArguments = ["-AppleLanguages", "(en)", "-AppleLocale", "en_US"]
Expand Down
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ PODS:
- hermes-engine (0.81.5):
- hermes-engine/Pre-built (= 0.81.5)
- hermes-engine/Pre-built (0.81.5)
- MathNotesMobileInk (0.3.11):
- MathNotesMobileInk (0.3.13):
- React-Core
- react-native-skia
- RCTDeprecation (0.81.5)
Expand Down Expand Up @@ -2552,7 +2552,7 @@ SPEC CHECKSUMS:
EXUpdatesInterface: 5adf50cb41e079c861da6d9b4b954c3db9a50734
FBLazyVector: e95a291ad2dadb88e42b06e0c5fb8262de53ec12
hermes-engine: 9f4dfe93326146a1c99eb535b1cb0b857a3cd172
MathNotesMobileInk: b740b9c34b667b4eac5be19cce8c830c76a87193
MathNotesMobileInk: 6a3869dac9092206e7aa17a83e854f73f4878835
RCTDeprecation: 943572d4be82d480a48f4884f670135ae30bf990
RCTRequired: 8f3cfc90cc25cf6e420ddb3e7caaaabc57df6043
RCTTypeSafety: 16a4144ca3f959583ab019b57d5633df10b5e97c
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"dependencies": {
"@expo/vector-icons": "^15.0.3",
"@mathnotes/mobile-ink": "file:vendor/mathnotes-mobile-ink-testflight-c56a32d.tgz",
"@mathnotes/mobile-ink": "file:vendor/mathnotes-mobile-ink-0.3.13.tgz",
"@react-native-async-storage/async-storage": "2.2.0",
"@shopify/react-native-skia": "2.2.12",
"expo": "54.0.34",
Expand Down
16 changes: 16 additions & 0 deletions scripts/catalogStore.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ import {
createCatalogStore,
parseCatalog,
} from '../src/services/catalogStore.ts';
import { paperBackgroundType } from '../src/utils/paperSpacing.ts';

test('line spacing survives catalog and older notes retain their original paper', () => {
const input = {version: 1, folders: [], notes: [
{id: 'old', backgroundType: 'lined'},
{id: 'new', backgroundType: 'lined', lineSpacing: 'narrow'},
{id: 'custom', backgroundType: 'lined', lineSpacing: 'custom-47'},
{id: 'invalid', backgroundType: 'lined', lineSpacing: 'invalid'},
]};
const notes = parseCatalog(JSON.stringify(parseCatalog(JSON.stringify(input)))).notes;
assert.equal(paperBackgroundType(notes[0].backgroundType, notes[0].lineSpacing), 'lined');
assert.equal(paperBackgroundType(notes[1].backgroundType, notes[1].lineSpacing), 'lined-narrow');
assert.equal(paperBackgroundType(notes[2].backgroundType, notes[2].lineSpacing), 'lined-custom-47');
assert.equal(paperBackgroundType(notes[3].backgroundType, notes[3].lineSpacing), 'lined');
assert.equal(paperBackgroundType('pdf', 'compact'), 'pdf');
});

test('catalog reload preserves composed thumbnail versions and still accepts old notes', () => {
const catalog = parseCatalog(JSON.stringify({
Expand Down
18 changes: 18 additions & 0 deletions scripts/exportService.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ts from 'typescript';
import { indexAssetsByPage } from '../src/utils/continuousAssets.ts';
import { buildPdfHtml } from '../src/services/pdfExportHtml.ts';
import { overlayLayerBoundaries } from '../src/utils/visualLayerOrder.ts';
import { pageBackgroundType } from '../src/utils/paperSpacing.ts';

const source = ts.transpileModule(
readFileSync(new URL('../src/services/exportService.ts', import.meta.url), 'utf8'),
Expand Down Expand Up @@ -90,6 +91,7 @@ function harness(files = {}, { mergePdfFiles } = {}) {
if (name === '@mathnotes/mobile-ink') return mobileInk;
if (name === '../utils/continuousAssets') return { indexAssetsByPage };
if (name === '../utils/visualLayerOrder') return { overlayLayerBoundaries };
if (name === '../utils/paperSpacing') return { pageBackgroundType };
if (name === './pdfExportHtml') {
return {
buildPdfHtml,
Expand All @@ -113,6 +115,22 @@ function harness(files = {}, { mergePdfFiles } = {}) {
};
}

test('exports the note paper spacing while keeping PDF backgrounds intact', async () => {
const h = harness();
const data = notebook([{pageType: undefined}, {pageType: 'pdf'}]);
const result = await h.exportNotebookAsPdf({ data, filename: 'paper', backgroundType: 'lined-narrow' });
assert.equal(result.ok, true);
assert.deepEqual(Array.from(h.batchCalls[0][1]), ['lined-narrow', 'pdf']);
});

test('does not apply an imported PDF background to a subsequently added blank page', async () => {
const h = harness();
const data = notebook([{pageType: 'pdf'}, {pageType: undefined}]);
const result = await h.exportNotebookAsPdf({ data, filename: 'mixed', backgroundType: 'pdf', pdfBackgroundUri: 'file:///note.pdf' });
assert.equal(result.ok, true);
assert.deepEqual(Array.from(h.batchCalls[0][1]), ['pdf', 'plain']);
});

test('a three-page PDF includes a photo and typed text on their original page', async () => {
const photo = 'file:///notes/photo.jpg';
const h = harness({ [photo]: 'cGhvdG8=' });
Expand Down
2 changes: 2 additions & 0 deletions scripts/noteThumbnails.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { readFileSync } from 'node:fs';
import test from 'node:test';
import vm from 'node:vm';
import ts from 'typescript';
import * as paperSpacing from '../src/utils/paperSpacing.ts';

const source = ts.transpileModule(
readFileSync(new URL('../src/services/notesRepo.ts', import.meta.url), 'utf8'),
Expand Down Expand Up @@ -39,6 +40,7 @@ function harness({ writeOk = true, renderFails = false, render = async () => com
};
if (name === '../i18n') return { t: { common: { untitled: 'Untitled' } } };
if (name === '../utils/id') return {};
if (name === '../utils/paperSpacing') return paperSpacing;
if (name === './catalogStore') return {};
if (name === './pdfStorage' || name === './imageInsertStorage') return {};
throw new Error('Unexpected import: ' + name);
Expand Down
10 changes: 10 additions & 0 deletions scripts/thumbnailRendering.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import vm from 'node:vm';
import ts from 'typescript';
import { createPromiseQueue } from '../src/utils/promiseQueue.ts';
import { imageLayerOrder, overlayLayerBoundaries, textLayerOrder } from '../src/utils/visualLayerOrder.ts';
import { pageBackgroundType } from '../src/utils/paperSpacing.ts';

const require = createRequire(import.meta.url);
const initCanvasKit = require('canvaskit-wasm/bin/full/canvaskit.js');
Expand Down Expand Up @@ -53,6 +54,7 @@ function harness({ nativeFails = false, nativeParagraphBuilder = false, nativeIm
vm.runInNewContext(source, { exports, require(name) {
if (name === '../utils/promiseQueue') return { createPromiseQueue };
if (name === '../utils/visualLayerOrder') return { imageLayerOrder, overlayLayerBoundaries, textLayerOrder };
if (name === '../utils/paperSpacing') return { pageBackgroundType };
if (name === 'react-native') return { Platform: { OS: 'ios' } };
if (name === './pdfUtilsModule') return { PDFUtilsModule: nativeImage ? {
readImageForThumbnail: nativeImage,
Expand Down Expand Up @@ -111,6 +113,14 @@ test('ink-only thumbnails are rendered from the saved page even without a previe
assert.equal(await h.createPageThumbnail(undefined), null);
});

test('thumbnail paper follows the note spacing even when the page is marked plain', async () => {
const h = harness();
await h.createPageThumbnail(page([], {pageType: 'plain'}), 'lined-narrow');
assert.equal(h.nativeCalls[0][1][0], 'lined-narrow');
await h.createPageThumbnail(page([photo()], {pageType: 'plain'}), 'lined-compact');
assert.equal(h.nativeCalls[1][1][0], 'lined-compact');
});

test('PDF-only thumbnails render the specified page and source', async () => {
const h = harness();
assert.equal(await h.createPageThumbnail(page([], {previewUri: undefined, pageType: 'pdf', pdfPageNumber: 3}),
Expand Down
Loading
Loading