How do the backspace and delete keys work in CKEditor? If I have an iframe in the editable area, and have my cursor next to it, hitting backspace/delete deletes the iframe/removes its HTML code from there.
What I was unable to get was where is the code for this behavior? Where on hitting backspace the range is shrunken to the iframe and it was removed.
Please point me in the right direction of where this happens in the source code.
There is something about delete
oKeystrokeHandler.SetKeystrokes
But i don't about that behavior
var FCKEnterKey = function( targetWindow, enterMode, shiftEnterMode, tabSpaces )
{
this.Window = targetWindow ;
this.EnterMode = enterMode || 'p' ;
this.ShiftEnterMode = shiftEnterMode || 'br' ;
// Setup the Keystroke Handler.
var oKeystrokeHandler = new FCKKeystrokeHandler( false ) ;
oKeystrokeHandler._EnterKey = this ;
oKeystrokeHandler.OnKeystroke = FCKEnterKey_OnKeystroke ;
oKeystrokeHandler.SetKeystrokes( [
[ 13 , 'Enter' ],
[ SHIFT + 13, 'ShiftEnter' ],
[ 8 , 'Backspace' ],
[ CTRL + 8 , 'CtrlBackspace' ],
[ 46 , 'Delete' ]
] ) ;
this.TabText = '' ;
// Safari by default inserts 4 spaces on TAB, while others make the editor
// loose focus. So, we need to handle it here to not include those spaces.
if ( tabSpaces > 0 || FCKBrowserInfo.IsSafari )
{
while ( tabSpaces-- )
this.TabText += '\xa0' ;
oKeystrokeHandler.SetKeystrokes( [ 9, 'Tab' ] );
}
oKeystrokeHandler.AttachToElement( targetWindow.document ) ;
}
http://code.google.com/p/easyfckeditor/source/browse/trunk/src/main/java/oh/how/easy/fck/js/fckeditor/editor/_source/classes/fckenterkey.js?r=2
Related
I'm trying to trigger autocomplete to show itself after certain words are entered and finalized with a space which does work but only after double tapping space. It does momentarily show the autocomplete when you press space once but then disappears. Only after tapping space again does it show autocomplete and stays. Putting in print() statements to check if it's triggering on the first space does show it works fine but why it closes straight away, I don't know.
Current code:
class ScriptListener(sublime_plugin.EventListener):
commands = [
'&Command1',
'&Command2'
]
Command1_completions = [
'param1=',
'param2='
]
Command2_completions = [
'param1=',
'param2='
]
last_word = ""
current_row = ""
def on_query_completions(self, view, prefix, locations):
if not view.match_selector(locations[0], "source.script"):
return None
if self.last_word == self.commands[0] or self.commands[0] in self.current_row:
return self._remove_known_arguments(self.Command1_completions)
elif self.last_word == self.commands[1] or self.commands[1] in self.current_row:
return self._remove_known_arguments(self.Command2_completions)
else:
return None
def on_modified(self, view):
for region in view.sel():
if (' ' in view.substr(view.word(region))):
self.current_row = view.substr(view.line(view.sel()[0]))
if any(command in self.current_row for command in self.commands):
view.run_command("auto_complete")
else:
self.last_word = view.substr(view.word(region))
def on_selection_modified(self, view):
#Get current row
self.current_row = view.substr(view.line(view.sel()[0]))
def _remove_known_arguments(self, comp_list):
for arg in comp_list:
if (arg in self.current_row):
comp_list.remove(arg)
return comp_list
I have following simple code:
Red []
view [
text "Value of x:" f1: field "" return
text "Value of y:" f2: field "" return
text "Read Sum:" tt: text "" return
button "Calculate" [
tt/text: to-string ((to-integer f1/text) + (to-integer f2/text)) ]
button "Quit" [quit] ]
How can I add code so that one can move between different fields using TAB key? Apparently, this works in Rebol ( http://www.rebol.com/how-to/fields.html ) but is not working here.
according gitter archive
handle-key: function [e prev-fld next-fld][
k: e/key
if k = tab [
either e/shift? [win/selected: prev-fld][win/selected: next-fld]
]
]
view [
text "Value of x:" f1: field "" on-key [handle-key event tt f2] return
text "Value of y:" f2: field "" on-key [handle-key event f1 tt] return
text "Read Sum:" tt: text "" on-key [handle-key event f2 f1] return
button "Calculate" [
tt/text: to-string ((to-integer f1/text) + (to-integer f2/text))
]
button "Quit" [quit]
do [win: self win/selected: f1]
]
To play at Stretch the word, I've defined the following words, to try to work at the problem via the same method as this answer:
USING: kernel math sequences sequences.repeating ;
IN: stretch-words
! "bonobo" -> { "b" "bo" "bon" "bono" "bonob" "bonobo" }
: ascend-string ( string -- ascending-seqs )
dup length 1 + iota [ 0 swap pick subseq ] map
[ "" = not ] filter nip ;
! expected: "bonobo" -> "bonoobbooo"
! actual: "bonobo" -> "bbbooonnnooobbbooo"
: stretch-word ( string -- stretched )
dup ascend-string swap zip
[
dup first swap last
[ = ] curry [ dup ] dip count
repeat
] map last ;
stretch-word is supposed to repeat a character in a string by the number of times it's appeared up to that position in the string. However, my implementation is repeating all instances of the 1string it gets.
I have the feeling this is easily implementable in Factor, but I can't quite figure it out. How do I make this do what I want?
Hm... not a great golf, but it works...
First, I made a minor change to ascend-string so it leaves the string on the stack:
: ascend-string ( string -- string ascending-seqs )
dup length 1 + iota [ 0 swap pick subseq ] map
[ "" = not ] filter ;
So stretch-word can work like this:
: stretch-word ( string -- stretched )
ascend-string zip ! just zip them in the same order
[
first2 over ! first2 is the only golf I could make :/
[ = ] curry count ! same thing
swap <array> >string ! make an array of char size count and make it a string
] map concat ; ! so you have to join the pieces
Edit:
I think the problem was using repeat to do the job.
: ascend-string ( string -- seqs )
"" [ suffix ] { } accumulate*-as ;
: counts ( string -- counts )
dup ascend-string [ indices length ] { } 2map-as ;
: stretch-word ( string -- stretched )
[ counts ] keep [ <string> ] { } 2map-as concat ;
"bonobo" stretch-word print
bonoobbooo
indices length could also be [ = ] with count
How can I use existing combinators to refactor this code so that regex will become argument to be partially applied and resulting quotation will have same identical stack effects as ls (x -- )?
USING: io.directories locals sequences accessors math
prettyprint kernel io.files.info io.directories.hierarchy
combinators.short-circuit regexp
;
IN: flac
:: job ( step path -- )
path
[ [ step call ] each ]
with-directory-entries
; inline
:: lsc ( x c -- ) x c call [ x . ] when ; inline
:: ls ( x -- )
x
[ {
[ directory? ]
[ name>> directory-tree-files
[ ".*[.]flac" <regexp> matches? ]
filter length 0 =
]
}
1&&
]
lsc
;
First of all, in the original code, it looks like x is a directory-entry. If x is required to stay as a directory-entry, then it is impossible to refactor out the regex as an argument, after all there's nowhere to put it! If x is allowed to change to, say a string with the regex embedded, or a collection or object, you can then make the regex part of the single argument -- x.
The following solution assumes x can be changed into a tuple object with "dir-entry" and "regex" as slots:
:: ls ( x -- )
x
[ dir-entry>> directory? ].
[
dir-entry>> name>> directory-tree-files
[ [ x regex>> <regexp> matches? ] any? ] [ drop x dir-entry>> ] when .
] smart-when* ;
I would like to dynamically add a button to the layout of a view, with the actor causing this addition belonging to a button that is already part of the layout.
I started with this:
REBOL [title: "Dynamic Button Addition"]
tilesize: 60x60
curtile: 1
stylize [
p: button [
facets: [init-size: tilesize max-size: tilesize]
actors: [
on-action: [
++ curtile
append tiles compose [ p (to-string curtile) ]
print ? tiles/options/content
v/redraw
]
]
]
]
v: [
tiles: hgroup [ p "1" ]
]
view v
...which does not appear to have the value of tiles/options/content change with each click.
I can get it to change if make these changes:
append tiledata compose [ p (to-string curtile) ]
and
tiledata: [ p "1" ]
v: [
tiles: hgroup tiledata
However, this does not cause any change on screen. If I replace the last four lines with this:
v: view [
tiles: hgroup tiledata
]
...so that v is now the view rather than the view's layout, I get this error when I click:
** Script error: v has no value
** Where: actor all foreach do-actor unless do-face if actor all foreach do-actor if do-event do-event if do-event either -apply- wake-up loop -apply- wait forever try do-events if view do either either either -apply-
** Near: actor face :data
This makes sense to me, because v is not yet done being defined, until I exit the program, IIUC.
How, then, can I make changes to v before the program ends, but after it's been passed to view?
Not very nice, but working if you replace
v/redraw
with these two lines
unview/all
view v
And there is a real dynamic example on how to update a layout that has already be viewed
I will simplify it
stylize [
tbox: hpanel [
actors: [
on-make: [
append face/options [
content: [
]
]
do-actor/style face 'on-make none 'hpanel
]
]
]
]
view/across [
button "button 1"
on-action [
append-content test compose [
button ( join "button " 2 + length? test/gob)
]
]
test: tbox
]