firefox-devtools / devtools-core

:rocket: Packages for Firefox DevTools

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Do not toggle object inspector nodes when selecting text

Loirooriol opened this issue · comments

  1. Open the console
  2. Enter inspect({a: () => {}})
▼ {…}
  ▶ a: function a()
​  ▶ __proto__: Object { … }
  1. Select fun

Before you can e.g. copy it, the property is expanded and fun disappears:

▼ {…}
  ▼ a: a()
     length: 0
     name: "a"
​  ▶ __proto__: Object { … }

@weilonge this might be a good one to work on if you plan to contribute here :)

@nchevobbe Does this mean that there should be the string "function" in "a: a()"? Like this?

▼ {…}
  ▼ a: **function** a()
     length: 0
     name: "a"
​  ▶ __proto__: Object { … }

@weilonge not really, it means that in https://github.com/devtools-html/devtools-core/blob/b39a79d112b2c99b800e2ad33f1c611904de9cdc/packages/devtools-reps/src/object-inspector/index.js#L369, if we have a text selection going on, we should not call setExpanded (https://github.com/devtools-html/devtools-core/blob/b39a79d112b2c99b800e2ad33f1c611904de9cdc/packages/devtools-reps/src/object-inspector/index.js#L372).

And somehow make a test to make sure we don't regress that.
You can reproduce the bug with the Reps test app (cd packages/devtools-reps && yarn && yarn start)

I was thinking something like

if (getSelection().isCollapsed) {
  // toggle node
} else {
  // do nothing
}