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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Version must be kept in-sync between [`package.json`](package.json) and [`wxt.config.js`](wxt.config.ts).

## [Unreleased]
### Fixed
- We don't show edited comments in the popup table anymore. ([#110](https://github.com/diffplug/gitcasso/pull/110))

## [1.1.0] - 2025-10-07
### Added
Expand Down
14 changes: 10 additions & 4 deletions src/entrypoints/background.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type {
CommentEvent,
CommentEventType,
CommentSpot,
import {
type CommentEvent,
type CommentEventType,
type CommentSpot,
DRAFT_STORAGE_UNSUPPORTED,
} from "@/lib/enhancer"
import { type DraftStats, statsFor } from "@/lib/enhancers/draft-stats"
import { logger } from "@/lib/logger"
Expand Down Expand Up @@ -51,6 +52,11 @@ export function handleCommentEvent(
return CLOSE_MESSAGE_PORT
}

// Skip storage for spots that don't support draft history
if (message.spot.unique_key === DRAFT_STORAGE_UNSUPPORTED) {
return CLOSE_MESSAGE_PORT
}

switch (message.type) {
case "ENHANCED": {
// track the draft
Expand Down
37 changes: 37 additions & 0 deletions src/lib/enhancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,40 @@ export interface CommentEnhancer<Spot extends CommentSpot = CommentSpot> {
/** The default title of a row */
tableTitle(spot: Spot): string
}

/**
* Special sentinel value for unique_key indicating that draft history
* should not be stored for this spot. Spots with this unique_key will:
* - Still be enhanced with OverType
* - NOT be stored in the background service's openSpots map
* - NOT appear in the popup table
*/
export const DRAFT_STORAGE_UNSUPPORTED = "DRAFT_STORAGE_UNSUPPORTED" as const

/**
* Abstract base class for enhancers that return spots with DRAFT_STORAGE_UNSUPPORTED.
* Table methods throw exceptions since such spots won't appear in the table.
*/
export abstract class CommentEnhancerNoDraftHistory<
Spot extends CommentSpot = CommentSpot,
> implements CommentEnhancer<Spot>
{
abstract forSpotTypes(): string[]
abstract tryToEnhance(
textarea: HTMLTextAreaElement,
location: StrippedLocation
): Spot | null
abstract enhance(textarea: HTMLTextAreaElement, spot: Spot): OverTypeInstance

tableUpperDecoration(_spot: Spot): never {
throw new Error(
"tableUpperDecoration should not be called for DRAFT_STORAGE_UNSUPPORTED spots"
)
}

tableTitle(_spot: Spot): never {
throw new Error(
"tableTitle should not be called for DRAFT_STORAGE_UNSUPPORTED spots"
)
}
}
45 changes: 9 additions & 36 deletions src/lib/enhancers/github/GitHubEditEnhancer.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import OverType, { type OverTypeInstance } from "overtype"
import type React from "react"
import type {
CommentEnhancer,
CommentSpot,
StrippedLocation,
import {
CommentEnhancerNoDraftHistory,
type CommentSpot,
DRAFT_STORAGE_UNSUPPORTED,
type StrippedLocation,
} from "@/lib/enhancer"
import { logger } from "@/lib/logger"
import { fixupOvertype, modifyDOM } from "../overtype-misc"
import {
commonGitHubOptions,
Expand All @@ -22,7 +21,7 @@ export interface GitHubEditSpot extends CommentSpot {
type: typeof GH_EDIT
}

export class GitHubEditEnhancer implements CommentEnhancer<GitHubEditSpot> {
export class GitHubEditEnhancer extends CommentEnhancerNoDraftHistory<GitHubEditSpot> {
forSpotTypes(): string[] {
return [GH_EDIT]
}
Expand All @@ -44,15 +43,10 @@ export class GitHubEditEnhancer implements CommentEnhancer<GitHubEditSpot> {
if (itemId) {
// Exclude textareas within Shared-module__CommentBox (those are for adding new comments, not editing)
if (!isInProjectCommentBox(textarea)) {
const unique_key = `github.com:project-draft:${itemId}:edit-body`
logger.debug(
`${this.constructor.name} enhanced project draft body textarea`,
unique_key
)
return {
isIssue: true,
type: GH_EDIT,
unique_key,
unique_key: DRAFT_STORAGE_UNSUPPORTED,
}
}
}
Expand All @@ -63,15 +57,10 @@ export class GitHubEditEnhancer implements CommentEnhancer<GitHubEditSpot> {
// Edit mode: empty placeholder
// Add new comment mode: has placeholder "Add your comment here..." or similar
if (!textarea.placeholder || textarea.placeholder.trim() === "") {
const unique_key = `github.com:${issueInfo.slug}:${issueInfo.number}:edit-comment`
logger.debug(
`${this.constructor.name} enhanced project issue comment edit textarea`,
unique_key
)
return {
isIssue: true,
type: GH_EDIT,
unique_key,
unique_key: DRAFT_STORAGE_UNSUPPORTED,
}
}
}
Expand All @@ -86,9 +75,6 @@ export class GitHubEditEnhancer implements CommentEnhancer<GitHubEditSpot> {
if (!match) {
return null
}
const [, owner, repo, numberStr] = match
const number = parseInt(numberStr!, 10)
const unique_key = `github.com:${owner}/${repo}:${number}:edit-body`

// Only enhance textareas that are for editing issue/PR body
const isIssueBodyRootEdit = textarea.closest(".react-issue-body")
Expand All @@ -102,15 +88,10 @@ export class GitHubEditEnhancer implements CommentEnhancer<GitHubEditSpot> {
if (!isIssueBodyRootEdit && !isIssueBodyCommentEdit && !isPRBodyEdit) {
return null
}

logger.debug(
`${this.constructor.name} enhanced issue/PR body textarea`,
unique_key
)
return {
isIssue: !!(isIssueBodyRootEdit || isIssueBodyCommentEdit),
type: GH_EDIT,
unique_key,
unique_key: DRAFT_STORAGE_UNSUPPORTED,
}
}

Expand All @@ -128,12 +109,4 @@ export class GitHubEditEnhancer implements CommentEnhancer<GitHubEditSpot> {
)
return overtype
}

tableUpperDecoration(_spot: GitHubEditSpot): React.ReactNode {
return <span>N/A</span>
}

tableTitle(_spot: GitHubEditSpot): string {
return "N/A"
}
}
9 changes: 8 additions & 1 deletion tests/corpus-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ vi.mock("overtype", () => {
})

import { describe as baseDescribe, test as baseTest, expect } from "vitest"
import type { StrippedLocation } from "@/lib/enhancer"
import {
DRAFT_STORAGE_UNSUPPORTED,
type StrippedLocation,
} from "@/lib/enhancer"
import { EnhancerRegistry } from "../src/lib/registries"
import type { CORPUS } from "./corpus/_corpus-index"
import { cleanupDOM, setupDOM } from "./corpus-utils"
Expand Down Expand Up @@ -94,6 +97,10 @@ export function tableUI() {
const enhanced = enhancers.tryToEnhance(textarea, location)
const forValue = `id=${textarea.id} name=${textarea.name} className=${textarea.className}`
if (enhanced) {
// Skip spots that don't support table display (DRAFT_STORAGE_UNSUPPORTED)
if (enhanced.spot.unique_key === DRAFT_STORAGE_UNSUPPORTED) {
continue
}
uiResults.push({
for: forValue,
title: enhanced.enhancer.tableTitle(enhanced.spot),
Expand Down
16 changes: 8 additions & 8 deletions tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports[`github detection > gh_issue_edit:should detect correct spots 1`] = `
"spot": {
"isIssue": true,
"type": "GH_EDIT",
"unique_key": "github.com:diffplug/gitcasso:56:edit-body",
"unique_key": "DRAFT_STORAGE_UNSUPPORTED",
},
},
{
Expand All @@ -47,15 +47,15 @@ exports[`github detection > gh_issue_edit_multiple:should detect correct spots 1
"spot": {
"isIssue": true,
"type": "GH_EDIT",
"unique_key": "github.com:diffplug/testing-deletable:3:edit-body",
"unique_key": "DRAFT_STORAGE_UNSUPPORTED",
},
},
{
"for": "id=:r8k: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input",
"spot": {
"isIssue": true,
"type": "GH_EDIT",
"unique_key": "github.com:diffplug/testing-deletable:3:edit-body",
"unique_key": "DRAFT_STORAGE_UNSUPPORTED",
},
},
{
Expand Down Expand Up @@ -140,7 +140,7 @@ exports[`github detection > gh_pr_edit:should detect correct spots 1`] = `
"spot": {
"isIssue": false,
"type": "GH_EDIT",
"unique_key": "github.com:diffplug/gitcasso:58:edit-body",
"unique_key": "DRAFT_STORAGE_UNSUPPORTED",
},
},
{
Expand All @@ -166,7 +166,7 @@ exports[`github detection > gh_pr_edit_multiple:should detect correct spots 1`]
"spot": {
"isIssue": false,
"type": "GH_EDIT",
"unique_key": "github.com:diffplug/testing-deletable:5:edit-body",
"unique_key": "DRAFT_STORAGE_UNSUPPORTED",
},
},
{
Expand All @@ -178,7 +178,7 @@ exports[`github detection > gh_pr_edit_multiple:should detect correct spots 1`]
"spot": {
"isIssue": false,
"type": "GH_EDIT",
"unique_key": "github.com:diffplug/testing-deletable:5:edit-body",
"unique_key": "DRAFT_STORAGE_UNSUPPORTED",
},
},
{
Expand Down Expand Up @@ -228,7 +228,7 @@ exports[`github detection > gh_project_draft_edit:should detect correct spots 1`
"spot": {
"isIssue": true,
"type": "GH_EDIT",
"unique_key": "github.com:project-draft:129503329:edit-body",
"unique_key": "DRAFT_STORAGE_UNSUPPORTED",
},
},
]
Expand Down Expand Up @@ -257,7 +257,7 @@ exports[`github detection > gh_project_issue_edit:should detect correct spots 1`
"spot": {
"isIssue": true,
"type": "GH_EDIT",
"unique_key": "github.com:project-draft:129503239:edit-body",
"unique_key": "DRAFT_STORAGE_UNSUPPORTED",
},
},
{
Expand Down
61 changes: 1 addition & 60 deletions tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ exports[`github ui > gh_issue:should render correct UI elements 1`] = `

exports[`github ui > gh_issue_edit:should render correct UI elements 1`] = `
[
{
"for": "id=:rc3: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input",
"title": "N/A",
"upperDecoration": <span>
N/A
</span>,
},
{
"for": "id=:ra7: name=null className=prc-Textarea-TextArea-13q4j overtype-input",
"title": "Description",
Expand Down Expand Up @@ -65,20 +58,6 @@ exports[`github ui > gh_issue_edit:should render correct UI elements 1`] = `

exports[`github ui > gh_issue_edit_multiple:should render correct UI elements 1`] = `
[
{
"for": "id=:r76: name=null className=prc-Textarea-TextArea-13q4j overtype-input",
"title": "N/A",
"upperDecoration": <span>
N/A
</span>,
},
{
"for": "id=:r8k: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input",
"title": "N/A",
"upperDecoration": <span>
N/A
</span>,
},
{
"for": "id=:r5b: name=null className=prc-Textarea-TextArea-13q4j overtype-input",
"title": "Description",
Expand Down Expand Up @@ -165,13 +144,6 @@ exports[`github ui > gh_pr:should render correct UI elements 1`] = `

exports[`github ui > gh_pr_edit:should render correct UI elements 1`] = `
[
{
"for": "id=issue-3429313834-body name=pull_request[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit js-size-to-fit size-to-fit js-session-resumable CommentBox-input FormControl-textarea js-saved-reply-shortcut-comment-field focus-visible overtype-input",
"title": "N/A",
"upperDecoration": <span>
N/A
</span>,
},
{
"for": "id=new_comment_field name=comment[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit FormControl-textarea CommentBox-input js-size-to-fit size-to-fit js-session-resumable js-saved-reply-shortcut-comment-field overtype-input",
"title": "Feat/expand corpus
Expand Down Expand Up @@ -202,20 +174,6 @@ exports[`github ui > gh_pr_edit:should render correct UI elements 1`] = `

exports[`github ui > gh_pr_edit_multiple:should render correct UI elements 1`] = `
[
{
"for": "id=issue-3454672384-body name=pull_request[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit js-size-to-fit size-to-fit js-session-resumable CommentBox-input FormControl-textarea js-saved-reply-shortcut-comment-field overtype-input",
"title": "N/A",
"upperDecoration": <span>
N/A
</span>,
},
{
"for": "id=issuecomment-3335416053-body name=issue_comment[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit js-size-to-fit size-to-fit js-session-resumable CommentBox-input FormControl-textarea js-saved-reply-shortcut-comment-field focus-visible overtype-input",
"title": "N/A",
"upperDecoration": <span>
N/A
</span>,
},
{
"for": "id=new_comment_field name=comment[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit FormControl-textarea CommentBox-input js-size-to-fit size-to-fit js-session-resumable js-saved-reply-shortcut-comment-field overtype-input",
"title": "Update README.md
Expand Down Expand Up @@ -274,17 +232,7 @@ exports[`github ui > gh_project:should render correct UI elements 1`] = `[]`;

exports[`github ui > gh_project_draft:should render correct UI elements 1`] = `[]`;

exports[`github ui > gh_project_draft_edit:should render correct UI elements 1`] = `
[
{
"for": "id=:r5a: name=null className=prc-Textarea-TextArea-13q4j overtype-input",
"title": "N/A",
"upperDecoration": <span>
N/A
</span>,
},
]
`;
exports[`github ui > gh_project_draft_edit:should render correct UI elements 1`] = `[]`;

exports[`github ui > gh_project_issue:should render correct UI elements 1`] = `
[
Expand Down Expand Up @@ -316,13 +264,6 @@ exports[`github ui > gh_project_issue:should render correct UI elements 1`] = `

exports[`github ui > gh_project_issue_edit:should render correct UI elements 1`] = `
[
{
"for": "id=:rdh: name=null className=prc-Textarea-TextArea-13q4j overtype-input",
"title": "N/A",
"upperDecoration": <span>
N/A
</span>,
},
{
"for": "id=:rbs: name=null className=prc-Textarea-TextArea-13q4j overtype-input",
"title": "what about drafts?",
Expand Down