mirror of
https://invent.kde.org/graphics/okular
synced 2024-07-02 15:49:03 +00:00
Implemented AFNumber_Keystroke and AFPercent_Keystroke
This commit is contained in:
parent
71957e02f6
commit
160be52119
|
@ -162,8 +162,33 @@ function AFNumber_Format( nDec, sepStyle, negStyle, currStyle, strCurrency, bCur
|
||||||
|
|
||||||
function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
|
function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
|
||||||
{
|
{
|
||||||
// TODO
|
const completeValue = AFMergeChange(event);
|
||||||
return;
|
|
||||||
|
if (!completeValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var decSep = "\\.";
|
||||||
|
if (2 <= sepStyle && sepStyle <= 4)
|
||||||
|
{
|
||||||
|
decSep = ",";
|
||||||
|
}
|
||||||
|
if (event.willCommit)
|
||||||
|
{
|
||||||
|
const COMMIT_NUMBER_KEYSTROKE_RE_STR = "(\\+|\\-)?\\d*" + decSep + "?\\d+$";
|
||||||
|
// Check if it is a valid number with a correct decimal separator
|
||||||
|
const COMMIT_NUMBER_KEYSTROKE_RE = new RegExp(COMMIT_NUMBER_KEYSTROKE_RE_STR);
|
||||||
|
|
||||||
|
event.rc = COMMIT_NUMBER_KEYSTROKE_RE.test(completeValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const NOCOMMIT_NUMBER_KEYSTROKE_RE_STR = "^((\\+|\\-)?\\d*" + decSep + "?\\d*)$";
|
||||||
|
// Allow some flexibility while typing to allow only the decimal separator
|
||||||
|
const NOCOMMIT_NUMBER_KEYSTROKE_RE = new RegExp(NOCOMMIT_NUMBER_KEYSTROKE_RE_STR);
|
||||||
|
event.rc = NOCOMMIT_NUMBER_KEYSTROKE_RE.test(completeValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function AFMakeNumber(string)
|
function AFMakeNumber(string)
|
||||||
|
@ -442,14 +467,7 @@ function AFPercent_Format( nDec, sepStyle )
|
||||||
|
|
||||||
function AFPercent_Keystroke( nDec, sepStyle )
|
function AFPercent_Keystroke( nDec, sepStyle )
|
||||||
{
|
{
|
||||||
if (event.willCommit) {
|
AFNumber_Keystroke(nDec, sepStyle);
|
||||||
event.rc = true
|
|
||||||
} else {
|
|
||||||
// Allow only numbers plus possible separators
|
|
||||||
// TODO disallow too many separators
|
|
||||||
// TODO Make separator locale-dependen/use sepStyle properly
|
|
||||||
event.rc = !isNaN(event.change) || event.change == "." || event.change == ","
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.popUpMenuEx = function() {
|
app.popUpMenuEx = function() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user