Open Bug 258291 Opened 17 years ago Updated 9 months ago

Empty undo/redo transaction is created when IME cannceled


(Core :: DOM: Editor, defect, P5)





(Reporter: masayuki, Unassigned)


(Blocks 1 open bug)


(Keywords: inputmethod)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8a3) Gecko/20040906
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8a3) Gecko/20040906

If IME is cannceled, the transaction is created.
But the transaction is empty.

Reproducible: Always
Steps to Reproduce:
1. Turn off the IME.
2. Type 'A'.
3. Turn on the IME.
4. Type any char.
5. Cancel the composition by hitting ESC key.
6. Turn off the IME.
7. Type 'B'.
Actual Results:  
1st Undo -> 'A'
2nd Undo -> 'A'    <== Empty transaction
3rd Undo -> ''

Expected Results:  
1st Undo -> 'A'
2nd Undo -> ''
1919 nsEditor::EndComposition(void)
1920 {
1921   if (!mInIMEMode) return NS_OK; // nothing to do
1923   nsresult result = NS_OK;
1925   // commit the IME transaction..we can get at it via the transaction mgr.
1926   // Note that this means IME won't work without an undo stack!
1927   if (mTxnMgr) 
1928   {
1929     nsCOMPtr<nsITransaction> txn;
1930     result = mTxnMgr->PeekUndoStack(getter_AddRefs(txn));  
1931     nsCOMPtr<nsIAbsorbingTransaction> plcTxn = do_QueryInterface(txn);
1932     if (plcTxn)
1933     {
1934       result = plcTxn->Commit();
1935     }
1936   }

The IME transaction is always commited.
Is there a way to tell the IME was cancelled?
I think that if IME is canceled, the transaction has no-string.
Hmm... I can't find where the transaction is created here.  Is there a way we
can ask it for the string it got?

Alternately, could we extend the IME api to have an explicit cancel instead of
just an "end"?
Ever confirmed: true
QA Contact: bugzilla → editor
Assignee: mozeditor → nobody
I've researched this.

Currently, nsEditor adds all transactions to its transaction manager when composition string is changed. I think that this is the root problem.

When I add Undo button on the toolbar by addon (, the undo button is enabled when I type first character of composition string. This is not good behavior. When composition is committed, the composition transaction should be added in the undo stack.

If we can separate the IME transaction from Undo stack, we can get more flexibility for handling composition. E.g., if web content's script moves selection, the composing string can move there. But it's too difficult to implement such behavior in current design. But I think if we can fix such issues, we can fix all strange behavior during composition with events or script. It's great improvement.

I think that nsEditor will be able to track composition which is started on it after bug 705057 fixed. Then, I will be able to work on this bug.
Depends on: 705057
We should really only touch the undo stack when an IME transaction is committed.  That sounds sane to m.

Bulk-downgrade of unassigned, >=5 years untouched DOM/Storage bugs' priority and severity.

If you have reason to believe this is wrong, please write a comment and ni :jstutte.

Severity: normal → S4
Priority: -- → P5
You need to log in before you can comment on or make changes to this bug.