Confirmed users
58
edits
m (→Proposed API) |
|||
Line 191: | Line 191: | ||
== Examples == | == Examples == | ||
var | var im = navigator.inputMethod; | ||
// Called when the user starts | // Called when the user starts editing an input field or switches to current IME | ||
im.onstart = function(event) { | |||
// Text input should start | |||
}; | |||
// Called when the user finishes editing an input field or switches to another IME. | |||
im.onfinish = function(event) { | |||
// Text input should end | |||
}; | }; | ||
// Insert a string at the current cursor position | // Insert a string at the current cursor position | ||
im.commitText('Hello world'); | |||
// Clear delete 5 characters before the cursor position. | // Clear delete 5 characters before the cursor position. | ||
im.deleteSurroundingText(-5, 5); | |||
// Get notified when the text content has changed. | // Get notified when the text content has changed. | ||
im.onsurroundingtextchange = function(beforeText, afterText) { | |||
console.log(beforeText + afterText); | |||
} | } | ||
// Move the cursor position | // Move the cursor position | ||
var position = 10; | var position = 10; | ||
im.setSelectionRange(position, position); | |||
// Hide the keyboard | // Hide the keyboard | ||
im.removeFocus(); | |||
== Related == | == Related == |