RoleForm: Don't let privilege labels break on dashes

This commit is contained in:
Johannes Meyer 2021-03-26 14:25:48 +01:00
parent be227fd61d
commit 68f101b015
2 changed files with 40 additions and 20 deletions

View File

@ -171,16 +171,24 @@ class RoleForm extends RepositoryForm
'autosubmit' => isset($spec['isFullPerm']), 'autosubmit' => isset($spec['isFullPerm']),
'disabled' => $hasFullPerm || $hasAdminPerm ?: null, 'disabled' => $hasFullPerm || $hasAdminPerm ?: null,
'value' => $hasFullPerm || $hasAdminPerm, 'value' => $hasFullPerm || $hasAdminPerm,
'label' => preg_replace( 'label' => isset($spec['label'])
// Adds a zero-width char after each slash to help browsers break onto newlines ? $spec['label']
'~(?<!<)/~', : join('', iterator_to_array(call_user_func(function ($segments) {
'/&#8203;', foreach ($segments as $segment) {
isset($spec['label']) ? $spec['label'] : preg_replace( if ($segment[0] === '/') {
'~^(\w+)(/.*)~', // Adds a zero-width char after each slash to help browsers break onto newlines
'<em>$1</em>$2', yield '/&#8203;';
$name yield '<span class="no-wrap">' . substr($segment, 1) . '</span>';
) } else {
), yield '<em>' . $segment . '</em>';
}
}
}, preg_split(
'~(/[^/]+)~',
$name,
-1,
PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY
)))),
'description' => isset($spec['description']) ? $spec['description'] : $name, 'description' => isset($spec['description']) ? $spec['description'] : $name,
'decorators' => array_merge( 'decorators' => array_merge(
array_slice(self::$defaultElementDecorators, 0, 3), array_slice(self::$defaultElementDecorators, 0, 3),
@ -220,16 +228,24 @@ class RoleForm extends RepositoryForm
'text', 'text',
$elementName, $elementName,
[ [
'label' => preg_replace( 'label' => isset($spec['label'])
// Adds a zero-width char after each slash to help browsers break onto newlines ? $spec['label']
'~(?<!<)/~', : join('', iterator_to_array(call_user_func(function ($segments) {
'/&#8203;', foreach ($segments as $segment) {
isset($spec['label']) ? $spec['label'] : preg_replace( if ($segment[0] === '/') {
'~^(\w+)(/.*)~', // Add zero-width char after each slash to help browsers break onto newlines
'<em>$1</em>$2', yield '/&#8203;';
$name yield '<span class="no-wrap">' . substr($segment, 1) . '</span>';
) } else {
), yield '<em>' . $segment . '</em>';
}
}
}, preg_split(
'~(/[^/]+)~',
$name,
-1,
PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY
)))),
'description' => $spec['description'], 'description' => $spec['description'],
'style' => $isUnrestricted ? 'text-decoration:line-through;' : '', 'style' => $isUnrestricted ? 'text-decoration:line-through;' : '',
'readonly' => $isUnrestricted ?: null 'readonly' => $isUnrestricted ?: null

View File

@ -45,6 +45,10 @@
} }
} }
.no-wrap {
white-space: nowrap;
}
.pull-right { .pull-right {
float: right; float: right;
} }