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
8 changes: 7 additions & 1 deletion media/CircleGraph/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const viewMode = {
selector: 1, // circle partition editor node selector
visq: 2, // quantization error viewer
// refer https://github.com/Samsung/ONE-vscode/issues/1350
visqselector: 3, // quantization error viewer which is able to select nodes
};

host.BrowserHost = class {
Expand Down Expand Up @@ -97,6 +98,8 @@ host.BrowserHost = class {
this._mode = viewMode.selector;
} else if (__viewMode === "visq") {
this._mode = viewMode.visq;
} else if (__viewMode === "visqselector") {
this._mode = viewMode.visqselector;
}
}

Expand Down Expand Up @@ -167,6 +170,9 @@ host.BrowserHost = class {
case "visq":
this._msgVisq(message);
break;
case "scrollToSelected":
this._view.setScrollToSelected(message.value);
break;
}
});

Expand Down Expand Up @@ -263,7 +269,7 @@ host.BrowserHost = class {
});

this._view.show("welcome spinner");
if (this._mode === viewMode.visq) {
if (this._mode === viewMode.visq || this._mode === viewMode.visqselector) {
// request visq data prior to model
// model is inside visq data
vscode.postMessage({ command: "visq" });
Expand Down
32 changes: 26 additions & 6 deletions media/CircleGraph/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,24 @@ view.View = class {
}
}

/**
* @brief called when it's needed to change scroll behaviour
*/
setScrollToSelected(value) {
this._scrollToSelected = value;
}

/**
* @brief toggleSelect will select or toggle select with CtrlKey down
* @param viewNode view.Node instance
* @note works on host mode is viewMode.selector
*/
toggleSelect(viewNode) {
if (viewNode && this._host._mode === viewMode.selector) {
if (
Copy link
Contributor

@dayo09 dayo09 May 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(optional) How about returning 'if not' condition here to reduce the level of condition?
Like,

if (!viewMode) {return}
if (this._host._mode === viewMode.selector || this._host._mode === viewMode.visqselector) {return}

// continuous logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dayo09
Thank you. Unfortunately there are 4 values, including visqselector, so inverting logic will still produce:

if (this._host._mode !== viewMode.viewer && this._host._mode !== viewMode.visq) {return}

// continuous logic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, if it's not 'viewMode', then this function don't need to proceed. Note that it's an 'and' condition. 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh. Sorry. I didn't immediately understand that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dayo09
fixed.

viewNode &&
(this._host._mode === viewMode.selector ||
this._host._mode === viewMode.visqselector)
) {
if (this._keyCtrl) {
// toggle selection
let index = this._selectionNodes.indexOf(viewNode);
Expand Down Expand Up @@ -585,7 +596,10 @@ view.View = class {

clearSelection() {
this._clearSelection();
if (host._mode === viewMode.selector) {
if (
host._mode === viewMode.selector ||
this._host._mode === viewMode.visqselector
) {
this._host.onView("selection");
}
}
Expand Down Expand Up @@ -1098,7 +1112,10 @@ view.View = class {
}

applyStyleSheetVisq(element) {
if (this._host._mode === viewMode.visq) {
if (
this._host._mode === viewMode.visq ||
this._host._mode === viewMode.visqselector
) {
let rules = [];
for (const styleSheet of this._host.document.styleSheets) {
if (styleSheet.title === "visq_style") {
Expand Down Expand Up @@ -1503,7 +1520,7 @@ view.Node = class extends grapher.Node {

_visq(node) {
const host = this.context.view._host;
if (host._mode !== viewMode.visq) {
if (host._mode !== viewMode.visq && host._mode !== viewMode.visqselector) {
return;
}

Expand Down Expand Up @@ -1535,7 +1552,7 @@ view.Node = class extends grapher.Node {
}
}
let visqSuffix = undefined;
if (host._mode === viewMode.visq) {
if (host._mode === viewMode.visq || host._mode === viewMode.visqselector) {
if (node.visq_index) {
let qstyle = `node-item-type-visq-${node.visq_index}`;
styles.push(qstyle);
Expand Down Expand Up @@ -1571,7 +1588,10 @@ view.Node = class extends grapher.Node {

if (host._mode === viewMode.viewer || host._mode === viewMode.visq) {
title.on("click", () => this.context.view.showNodeProperties(node, null));
} else if (host._mode === viewMode.selector) {
} else if (
host._mode === viewMode.selector ||
host._mode === viewMode.visqselector
) {
// toggle select with click
title.on("click", () => {
this.context.view.toggleSelect(this);
Expand Down