Skip to content

Change smart picker behavior#130

Open
chrip wants to merge 2 commits into
mainfrom
fix/issue-122-smart-picker-behavior
Open

Change smart picker behavior#130
chrip wants to merge 2 commits into
mainfrom
fix/issue-122-smart-picker-behavior

Conversation

@chrip

@chrip chrip commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

This introduced calling smart picker by keystroke "/" anywhere in a doc, ppt, or xls.
Details are in #122

For testing you need connector app and web-apps on the following branches:
https://github.com/Euro-Office/eurooffice-nextcloud/tree/fix/issue-122-smart-picker-behavior
https://github.com/Euro-Office/web-apps/tree/fix/issue-122-smart-picker-behavior

chrip added 2 commits June 18, 2026 17:45
…vior

Refs #122

- Rename button caption and tooltip from "Smart Picker" / "Ask Nextcloud
  Assistant" to "Add from Nextcloud" in all three editors
- On toolbar button click, insert "/" at cursor position before opening
  the picker, so the flow matches the Notes app slash-command UX
- When the user selects a result, the inserted "/" is replaced by the
  hyperlink via pluginMethod_InputText backspace + add_Hyperlink
- Replace sparkle icon with a plain "+" in the same stroke style as
  other toolbar icons (btn-inserthyperlink template)

Assisted-by: ClaudeCode:claude-sonnet-4-6
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
…t at cursor

Refs #122

Works together with the Euro-Office/eurooffice-nextcloud branch
"fix/issue-122-smart-picker-behavior" (host-side integration). Both
branches are required for the feature to work.

- Show the "Add from Nextcloud" toolbar button only while connected to a
  Nextcloud server: the button now defaults to hidden (visible:false) and
  is toggled by a new setSmartPickerAvailable host command (api.js +
  Gateway). The "Ask Nextcloud Assistant" context-menu item keeps its
  existing setAssistantAvailable gating.
- Trigger the picker by typing "/" in the editor body, layout-independent
  (e.key). In spreadsheets the keydown listener runs in the capture phase
  so it also fires while a cell is being edited.
- Replace the inserted/typed "/" with the selected result on success and
  leave it in place on cancel (new setSmartPickerCancel host command).
- Restore editor focus after insert and cancel via edit:complete.
- Spreadsheets: insert the link as text (cell hyperlinks are whole-cell),
  using isCellEdited to pick pluginMethod_InputText at the cursor while
  editing (re-focusing the cell input) vs asc_insertInCell on a selected
  cell; strip the "/" trigger and never fall into the formula path.
- Use a dedicated "+" icon (btn-nc-add / btn-big-nc-add) drawn in the
  standard 1px toolbar stroke and drop the old btn-nc-assistant sparkle.

Assisted-by: ClaudeCode:claude-sonnet-4-6
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
@chrip chrip requested a review from a team as a code owner June 19, 2026 13:57
@chrip chrip requested review from MonaAghili, j-base64 and moodyjmz and removed request for a team June 19, 2026 13:57
// on a selected cell and mid-edit (e.g. "asdf /"); _smartPickerReplace
// then drives the "/" removal on insert.
document.addEventListener('keydown', function(e) {
var key = e.key || (e.originalEvent && e.originalEvent.key);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I believe e.originalEvent only exists on jquery wrapped events
This is a native listener and e is already the KeyboardEvent
This fallback never runs Just var key = e.key

Comment on lines +1438 to +1446
// Not editing (selected cell): append to the committed cell
// text via the value path (no formula operators, so no "+");
// drop a trailing "/" trigger if present.
var cell = this.api.asc_getCellInfo && this.api.asc_getCellInfo();
var cur = (cell && cell.asc_getText && cell.asc_getText()) || '';
if (cur.slice(-1) === '/') {
cur = cur.slice(0, -1);
}
this.api.asc_insertInCell(cur + data, Asc.c_oAscPopUpSelectorType.None);

@MonaAghili MonaAghili Jun 24, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The comment says "no formula operators so no +", but that's not really the issue here.
As I investigate
asc_getText() internally calls getValueForEdit() (WorksheetView.js:13669) which it returns the same value shown in the formula bar. For formula cells that's the formula itself (for example, =SUM(A1:A10)) not the evaluated result

As a result cur + data becomes something like:

=SUM(A1:A10)https://example.com (the formula source with the =) when you pass that to asc_insertInCell the SDK sees a string starting with = and tries to parse it as a formula
The url appended after it makes it syntactically invalid → the cell becomes #NAME?. The original formula is gone.

Even for non formula cells the behavior isn't ideal! If the cell contains 42 concatenation produces 42https://... converting the numeric value into plain text instead of preserving it as a number

Suggestion: if the cell is empty (cur === '') just insert data directly.

If the cell isn't empty, it's not obvious what the expected behavior should be. Should we replace the existing value append to it or reject the operation? It would be better to decide that explicitly instead of silently producing incorrect results for non-empty cells.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants