Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F121689390
PhabricatorKeyboardRemarkupRule.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Jul 13, 04:42
Size
4 KB
Mime Type
text/x-php
Expires
Tue, Jul 15, 04:42 (2 d)
Engine
blob
Format
Raw Data
Handle
27374698
Attached To
rPH Phabricator
PhabricatorKeyboardRemarkupRule.php
View Options
<?php
final
class
PhabricatorKeyboardRemarkupRule
extends
PhutilRemarkupRule
{
public
function
getPriority
()
{
return
200.0
;
}
public
function
apply
(
$text
)
{
return
preg_replace_callback
(
'@{key
\b
((?:[^}
\\\\
]+|
\\\\
.)*)}@m'
,
array
(
$this
,
'markupKeystrokes'
),
$text
);
}
public
function
markupKeystrokes
(
array
$matches
)
{
if
(!
$this
->
isFlatText
(
$matches
[
0
]))
{
return
$matches
[
0
];
}
$keys
=
explode
(
' '
,
$matches
[
1
]);
foreach
(
$keys
as
$k
=>
$v
)
{
$v
=
trim
(
$v
,
"
\n
"
);
$v
=
preg_replace
(
'/
\\\\
(.)/'
,
'
\\
1'
,
$v
);
if
(!
strlen
(
$v
))
{
unset
(
$keys
[
$k
]);
continue
;
}
$keys
[
$k
]
=
$v
;
}
$special
=
array
(
array
(
'name'
=>
pht
(
'Command'
),
'symbol'
=>
"
\x
E2
\x
8C
\x
98"
,
'aliases'
=>
array
(
'cmd'
,
'command'
,
),
),
array
(
'name'
=>
pht
(
'Option'
),
'symbol'
=>
"
\x
E2
\x
8C
\x
A5"
,
'aliases'
=>
array
(
'opt'
,
'option'
,
),
),
array
(
'name'
=>
pht
(
'Shift'
),
'symbol'
=>
"
\x
E2
\x
87
\x
A7"
,
'aliases'
=>
array
(
'shift'
,
),
),
array
(
'name'
=>
pht
(
'Escape'
),
'symbol'
=>
"
\x
E2
\x
8E
\x
8B"
,
'aliases'
=>
array
(
'esc'
,
'escape'
,
),
),
array
(
'name'
=>
pht
(
'Up'
),
'symbol'
=>
"
\x
E2
\x
86
\x
91"
,
'heavy'
=>
"
\x
E2
\x
AC
\x
86"
,
'aliases'
=>
array
(
'up'
,
'arrow-up'
,
'up-arrow'
,
'north'
,
),
),
array
(
'name'
=>
pht
(
'Tab'
),
'symbol'
=>
"
\x
E2
\x
87
\x
A5"
,
'aliases'
=>
array
(
'tab'
,
),
),
array
(
'name'
=>
pht
(
'Right'
),
'symbol'
=>
"
\x
E2
\x
86
\x
92"
,
'heavy'
=>
"
\x
E2
\x
9E
\x
A1"
,
'aliases'
=>
array
(
'right'
,
'right-arrow'
,
'arrow-right'
,
'east'
,
),
),
array
(
'name'
=>
pht
(
'Left'
),
'symbol'
=>
"
\x
E2
\x
86
\x
90"
,
'heavy'
=>
"
\x
E2
\x
AC
\x
85"
,
'aliases'
=>
array
(
'left'
,
'left-arrow'
,
'arrow-left'
,
'west'
,
),
),
array
(
'name'
=>
pht
(
'Down'
),
'symbol'
=>
"
\x
E2
\x
86
\x
93"
,
'heavy'
=>
"
\x
E2
\x
AC
\x
87"
,
'aliases'
=>
array
(
'down'
,
'down-arrow'
,
'arrow-down'
,
'south'
,
),
),
array
(
'name'
=>
pht
(
'Up Right'
),
'symbol'
=>
"
\x
E2
\x
86
\x
97"
,
'heavy'
=>
"
\x
E2
\x
AC
\x
88"
,
'aliases'
=>
array
(
'up-right'
,
'upright'
,
'up-right-arrow'
,
'upright-arrow'
,
'arrow-up-right'
,
'arrow-upright'
,
'northeast'
,
'north-east'
,
),
),
array
(
'name'
=>
pht
(
'Down Right'
),
'symbol'
=>
"
\x
E2
\x
86
\x
98"
,
'heavy'
=>
"
\x
E2
\x
AC
\x
8A"
,
'aliases'
=>
array
(
'down-right'
,
'downright'
,
'down-right-arrow'
,
'downright-arrow'
,
'arrow-down-right'
,
'arrow-downright'
,
'southeast'
,
'south-east'
,
),
),
array
(
'name'
=>
pht
(
'Down Left'
),
'symbol'
=>
"
\x
E2
\x
86
\x
99"
,
'heavy'
=>
"
\x
E2
\x
AC
\x
8B"
,
'aliases'
=>
array
(
'down-left'
,
'downleft'
,
'down-left-arrow'
,
'downleft-arrow'
,
'arrow-down-left'
,
'arrow-downleft'
,
'southwest'
,
'south-west'
,
),
),
array
(
'name'
=>
pht
(
'Up Left'
),
'symbol'
=>
"
\x
E2
\x
86
\x
96"
,
'heavy'
=>
"
\x
E2
\x
AC
\x
89"
,
'aliases'
=>
array
(
'up-left'
,
'upleft'
,
'up-left-arrow'
,
'upleft-arrow'
,
'arrow-up-left'
,
'arrow-upleft'
,
'northwest'
,
'north-west'
,
),
),
);
$map
=
array
();
foreach
(
$special
as
$spec
)
{
foreach
(
$spec
[
'aliases'
]
as
$alias
)
{
$map
[
$alias
]
=
$spec
;
}
}
$is_text
=
$this
->
getEngine
()->
isTextMode
();
$parts
=
array
();
foreach
(
$keys
as
$k
=>
$v
)
{
$normal
=
phutil_utf8_strtolower
(
$v
);
if
(
isset
(
$map
[
$normal
]))
{
$spec
=
$map
[
$normal
];
}
else
{
$spec
=
array
(
'name'
=>
null
,
'symbol'
=>
$v
,
);
}
if
(
$is_text
)
{
$parts
[]
=
'['
.
$spec
[
'symbol'
].
']'
;
}
else
{
$parts
[]
=
phutil_tag
(
'kbd'
,
array
(
'title'
=>
$spec
[
'name'
],
),
$spec
[
'symbol'
]);
}
}
if
(
$is_text
)
{
$parts
=
implode
(
' + '
,
$parts
);
}
else
{
$glue
=
phutil_tag
(
'span'
,
array
(
'class'
=>
'kbd-join'
,
),
'+'
);
$parts
=
phutil_implode_html
(
$glue
,
$parts
);
}
return
$this
->
getEngine
()->
storeText
(
$parts
);
}
}
Event Timeline
Log In to Comment