-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add headless workspace comment class #7916
Merged
BeksOmega
merged 7 commits into
google:rc/v11.0.0
from
BeksOmega:feat/workspace-comment
Mar 15, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
13494da
feat: add empty definitions for comment class
BeksOmega 141be45
feat: implement constructor
BeksOmega 0e0ba0f
feat: add method implementations
BeksOmega 88bb764
feat: add own properties
BeksOmega dbac646
chore: add tsdoc
BeksOmega 1213bf2
fix: typos
BeksOmega b01b0ca
chore: cleanup TODOs
BeksOmega File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/** | ||
* @license | ||
* Copyright 2024 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import {Workspace} from '../workspace.js'; | ||
import {Size} from '../utils/size.js'; | ||
import {Coordinate} from '../utils/coordinate.js'; | ||
import * as idGenerator from '../utils/idgenerator.js'; | ||
|
||
export class WorkspaceComment { | ||
/** The unique identifier for this comment. */ | ||
public readonly id: string; | ||
|
||
/** The text of the comment. */ | ||
private text = ''; | ||
|
||
/** The size of the comment in workspace units. */ | ||
private size = new Size(120, 100); | ||
|
||
/** Whether the comment is collapsed or not. */ | ||
private collapsed = false; | ||
|
||
/** Whether the comment is editable or not. */ | ||
private editable = true; | ||
|
||
/** Whether the comment is movable or not. */ | ||
private movable = true; | ||
|
||
/** Whether the comment is deletable or not. */ | ||
private deletable = true; | ||
|
||
/** The location of the comment in workspace coordinates. */ | ||
private location = new Coordinate(0, 0); | ||
|
||
/** Whether this comment has been disposed or not. */ | ||
private disposed = false; | ||
|
||
/** | ||
* Constructs the comment. | ||
* | ||
* @param workspace The workspace to construct the comment in. | ||
* @param id An optional ID to give to the comment. If not provided, one will | ||
* be generated. | ||
*/ | ||
constructor( | ||
protected readonly workspace: Workspace, | ||
id?: string, | ||
) { | ||
this.id = id && !workspace.getCommentById(id) ? id : idGenerator.genUid(); | ||
|
||
// TODO(7909): Fire events. | ||
} | ||
|
||
/** Sets the text of the comment. */ | ||
setText(text: string) { | ||
this.text = text; | ||
} | ||
|
||
/** Returns the text of the comment. */ | ||
getText(): string { | ||
return this.text; | ||
} | ||
|
||
/** Sets the comment's size in workspace units. */ | ||
setSize(size: Size) { | ||
this.size = size; | ||
} | ||
|
||
/** Returns the comment's size in workspace units. */ | ||
getSize(): Size { | ||
return this.size; | ||
} | ||
|
||
/** Sets whether the comment is collapsed or not. */ | ||
setCollapsed(collapsed: boolean) { | ||
this.collapsed = collapsed; | ||
} | ||
|
||
/** Returns whether the comment is collapsed or not. */ | ||
isCollapsed(): boolean { | ||
return this.collapsed; | ||
} | ||
|
||
/** Sets whether the comment is editable or not. */ | ||
setEditable(editable: boolean) { | ||
this.editable = editable; | ||
} | ||
|
||
/** | ||
* Returns whether the comment is editable or not, respecting whether the | ||
* workspace is read-only. | ||
*/ | ||
isEditable(): boolean { | ||
return this.isOwnEditable() && !this.workspace.options.readOnly; | ||
} | ||
|
||
/** | ||
* Returns whether the comment is editable or not, only examining its own | ||
* state and ignoring the state of the workspace. | ||
*/ | ||
isOwnEditable(): boolean { | ||
return this.editable; | ||
} | ||
|
||
/** Sets whether the comment is movable or not. */ | ||
setMovable(movable: boolean) { | ||
this.movable = movable; | ||
} | ||
|
||
/** | ||
* Returns whether the comment is movable or not, respecting whether the | ||
* workspace is read-only. | ||
*/ | ||
isMovable() { | ||
return this.isOwnMovable() && !this.workspace.options.readOnly; | ||
} | ||
|
||
/** | ||
* Returns whether the comment is movable or not, only examining its own | ||
* state and ignoring the state of the workspace. | ||
*/ | ||
isOwnMovable() { | ||
return this.movable; | ||
} | ||
|
||
/** Sets whether the comment is deletable or not. */ | ||
setDeletable(deletable: boolean) { | ||
this.deletable = deletable; | ||
} | ||
|
||
/** | ||
* Returns whether the comment is deletable or not, respecting whether the | ||
* workspace is read-only. | ||
*/ | ||
isDeletable(): boolean { | ||
return this.isOwnDeletable() && !this.workspace.options.readOnly; | ||
} | ||
|
||
/** | ||
* Returns whether the comment is deletable or not, only examining its own | ||
* state and ignoring the state of the workspace. | ||
*/ | ||
isOwnDeletable(): boolean { | ||
return this.deletable; | ||
} | ||
|
||
/** Moves the comment to the given location in workspace coordinates. */ | ||
moveTo(location: Coordinate) { | ||
this.location = location; | ||
} | ||
|
||
/** Returns the position of the comment in workspace coordinates. */ | ||
getRelativeToSurfaceXY(): Coordinate { | ||
return this.location; | ||
} | ||
|
||
/** Disposes of this comment. */ | ||
dispose() { | ||
this.disposed = true; | ||
} | ||
|
||
/** Returns whether the comment has been disposed or not. */ | ||
isDisposed() { | ||
return this.disposed; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swapping these two is slightly better in case the workspace is readonly and the user decides to compute the traveling salesman problem in the
ownEditable
function, but i'll acknowledge this is minute :Pthe equivalent in
Block
also checks if the block has been disposed. do we need to do that here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to do that. Looks like in
Block
it was originally(this.workspace && !this.workspace.options.readonly)
which turned into!this.disposed && !this.workspace.options.readonly
which turned into!this.isDeadOrDying() && !this.workspace.options.readonly
.So I think it was originally just a type safety thing, and as we migrated code the logic got slightly confused :P
Theoretically something that is being disposed probably isn't editable? But it probably doesn't have a size or text either. I think it's fine to ignore this.