Closed Bug 843597 Opened 11 years ago Closed 10 years ago

ScratchpadManager.openScratchpad() puts the cursor at the bottom

Categories

(DevTools Graveyard :: Scratchpad, defect, P3)

defect

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 27

People

(Reporter: arantius, Unassigned)

Details

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0
Build ID: 20130215130331

Steps to reproduce:

I added a feature to Greasemonkey to use Scratchpad as the default script editor.
https://github.com/greasemonkey/greasemonkey/commit/4fab342c6e47af47b4ee38b011693845999ebe68#L3R1


Actual results:

I'm calling ScratchpadManager.openScratchpad() with a filename argument, which it seems to support -- but it doesn't read that file into the editor, so I'm also specifying the text argument.  Which it puts into the editor, but it then puts the cursor at the end of this text.


Expected results:

This is incongruent with the behavior that actually picking File>Open in Scratchpad displays: it puts the cursor at the top (as expected).  Pretty much every editor, when opening a new initial file at launch, or opening a file interactively, puts the cursor at the top of the file.

Either:
A) Supplying the filename argument to openScratchpad() should act exactly like picking that file after doing File>Open  (read its contents, put it in the editor, put the cursor at the top), or
B) The cursor should start at the top of the editor even when supplying initial text.
Component: Untriaged → Developer Tools: Scratchpad
Scratchpad.openScratchpad takes an optional `state` argument, which is an object that looks like:

> {
>   filename: "filename.js",
>   text: "// javascript code goes here",
>   executionContext: 1,
>   saved: true
> }

`executionContext` is 1 for content, 2 for browser
saved indicates whether there's a * next to the name (AKA editor is dirty)

If you use ScratchpadManager.openScratchpad with options like this then it should open with the cursor at the top instead of the bottom as you desire.
Status: UNCONFIRMED → RESOLVED
Closed: 11 years ago
Resolution: --- → WORKSFORME
That's exactly what I've always been doing:

https://github.com/greasemonkey/greasemonkey/blob/4fab342c6e47af47b4ee38b011693845999ebe68/modules/util/openInEditor.js#L18

Unless you're saying that the executionContext _must_ also be passed?
Status: RESOLVED → UNCONFIRMED
Resolution: WORKSFORME → ---
Oh hmm. I will investigate further.
You are absolutely right! I must have been seeing things.
Status: UNCONFIRMED → NEW
Ever confirmed: true
OS: Linux → All
Priority: -- → P3
Hardware: x86_64 → All
Version: 19 Branch → Trunk
As an interim solution until we get a fix landed, you can use `scratchpad.selectRange(0, 0)` (assuming you're not already doing this as a workaround).
Unfortunately, it does not always work. For example:
https://github.com/greasemonkey/greasemonkey/issues/1785
So what's the situation here after bug 912260 ?
Thanks!
Status: NEW → RESOLVED
Closed: 11 years ago10 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 27
Product: Firefox → DevTools
Product: DevTools → DevTools Graveyard
You need to log in before you can comment on or make changes to this bug.