Skip to content

Allow annotation creation without a prior selection#7952

Draft
david-yz-liu wants to merge 1 commit into
masterfrom
feature/annotation-without-selection
Draft

Allow annotation creation without a prior selection#7952
david-yz-liu wants to merge 1 commit into
masterfrom
feature/annotation-without-selection

Conversation

@david-yz-liu
Copy link
Copy Markdown
Collaborator

Proposed Changes

Enables graders to create annotations in MarkUs even when no region has been explicitly selected in the file viewer. Previously, all annotation creation options in the right-click context menu were disabled unless the grader had first highlighted text, dragged a box on an image, or drawn a region on a PDF.

When a grader right-clicks without a selection, the context menu now enables all annotation creation items. If the grader proceeds to create an annotation, a fallback selection is synthesized automatically:

  • Text/code files — a 1-character annotation at the first non-empty, non-whitespace line (column 0–1)
  • HTML/Jupyter/RMarkdown files — a 1-character annotation covering the first character of the first text node in the rendered iframe body
  • Image files — a 40×40 px square centred at the point where the user right-clicked (in image pixel coordinates, clamped to image bounds)
  • PDF files — a 40×40 px square centred at the point where the user right-clicked on the page (in percentage coordinates scaled by 100,000, with inverse-rotation correction applied)

If no fallback can be synthesized (empty file, HTML with no text content, PDF with no loaded pages, image with no dimensions), an alert is shown: "Cannot create annotation: the file has no content to annotate."

This change also fixes a pre-existing crash: window.annotation_manager is null for HTML files, causing the original beforeOpen handler to throw TypeError every time the context menu was opened on an HTML file.

Screenshots of your changes (if applicable)
Associated documentation repository pull request (if applicable)

Type of Change

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality) X
🐛 Bug fix (non-breaking change that fixes an issue) X
🎨 User interface change (change to user interface; provide screenshots)
♻️ Refactoring (internal change to codebase, without changing functionality)
🚦 Test update (change that only adds or modifies tests)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

Checklist

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.

After opening your pull request:

  • I have updated the project Changelog (this is required for all changes).
  • I have verified that the pre-commit.ci checks have passed.
  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported by Coveralls.
  • I have requested a review from a project maintainer.

Questions and Comments

When grading, the context menu previously disabled all annotation
creation options if no region was selected. Graders can now create
annotations at any time; a fallback selection is synthesized
automatically:

- Text/code: first character of the first non-empty line
- HTML/Jupyter: first character of the first text node in the iframe
- Image: 40×40 px box centred at the right-click position
- PDF: 40×40 box centred at the right-click position (with
  rotation correction), in COORDINATE_MULTIPLIER-scaled percentage space

If no fallback can be synthesized (empty file, no text content, etc.)
an I18n alert is shown instead of silently failing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@david-yz-liu david-yz-liu force-pushed the feature/annotation-without-selection branch from 2ae2eb0 to 261eec1 Compare May 16, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant