Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

message: Improve the copy codeblock and playground buttons.

Sayam Samale0d685ce9211
diff --git a/web/shared/icons/external-link.svg b/web/shared/icons/external-link.svg
new file mode 100644
index 00000000000..0347d0ca800
--- /dev/null
+++ b/web/shared/icons/external-link.svg
@@ -0,0 +1,4 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14" fill="none">
+ <path d="M2.33333 3.6665C2.15647 3.6665 1.98686 3.73675 1.86181 3.86181C1.73675 3.98686 1.6665 4.15647 1.6665 4.33333V11.6667C1.6665 11.8435 1.73675 12.0131 1.86181 12.1382C1.98686 12.2632 2.15647 12.3335 2.33333 12.3335H9.66666C9.84352 12.3335 10.0131 12.2632 10.1382 12.1382C10.2632 12.0131 10.3335 11.8435 10.3335 11.6667V7.66666C10.3335 7.29856 10.6319 7.00016 11 7.00016C11.3681 7.00016 11.6665 7.29856 11.6665 7.66666V11.6667C11.6665 12.1971 11.4558 12.7057 11.0808 13.0808C10.7057 13.4558 10.1971 13.6665 9.66666 13.6665H2.33333C1.80294 13.6665 1.29427 13.4558 0.919234 13.0808C0.544192 12.7057 0.333496 12.1971 0.333496 11.6667V4.33333C0.333496 3.80294 0.544192 3.29428 0.919234 2.91923C1.29428 2.54419 1.80294 2.3335 2.33333 2.3335H6.33333C6.70143 2.3335 6.99983 2.6319 6.99983 3C6.99983 3.36809 6.70143 3.6665 6.33333 3.6665H2.33333Z" fill="black"/>
+ <path d="M8.3335 0.999996C8.3335 0.631898 8.6319 0.333496 9 0.333496H13C13.3681 0.333496 13.6665 0.631898 13.6665 0.999996V5C13.6665 5.36809 13.3681 5.6665 13 5.6665C12.6319 5.6665 12.3335 5.36809 12.3335 5V2.60907L6.13795 8.80462C5.87766 9.0649 5.45566 9.0649 5.19538 8.80462C4.93509 8.54433 4.93509 8.12233 5.19538 7.86204L11.3909 1.6665H9C8.6319 1.6665 8.3335 1.36809 8.3335 0.999996Z" fill="black"/>
+</svg>
\ No newline at end of file
diff --git a/web/src/playground_links_popover.ts b/web/src/playground_links_popover.ts
index 7eb917ad406..5e40bcc63d6 100644
--- a/web/src/playground_links_popover.ts
+++ b/web/src/playground_links_popover.ts
@@ -111,22 +111,16 @@ function register_click_handlers(): void {
if (playground_info === undefined) {
return;
}
- // We do the code extraction here and set the target href expanding
- // the url_template with the extracted code. Depending on whether
- // the language has multiple playground links configured, a popover
- // is shown.
+ // We do the code extraction here and send user to the target destination,
+ // obtained by expanding the url_template with the extracted code.
+ // Depending on whether the language has multiple playground links configured,
+ // a popover is shown.
const extracted_code = $codehilite_div.find("code").text();
if (playground_info.length === 1 && playground_info[0] !== undefined) {
const url_template = url_template_lib.parse(playground_info[0].url_template);
- $view_in_playground_button.attr(
- "href",
- url_template.expand({code: extracted_code}),
- );
+ const playground_url = url_template.expand({code: extracted_code});
+ window.open(playground_url, "_blank", "noopener,noreferrer");
} else {
- // Remove the href attribute that was set when there was only
- // one playground link, so that it doesn't interfere with the
- // popover toggle when multiple playground links exist.
- $view_in_playground_button.removeAttr("href");
const playground_store = new Map<number, RealmPlaygroundWithURL>();
for (const playground of playground_info) {
const url_template = url_template_lib.parse(playground.url_template);
diff --git a/web/styles/rendered_markdown.css b/web/styles/rendered_markdown.css
index 80b8672a312..91b26f4ca40 100644
--- a/web/styles/rendered_markdown.css
+++ b/web/styles/rendered_markdown.css
@@ -738,6 +738,14 @@
&:hover .code-buttons-container {
visibility: visible;
}
+
+ /* Hide the code buttons container when the user is
+ clicking on the code block other than the buttons.
+ This allows the user to select part of the the code
+ without the buttons interfering with the selection. */
+ &:active .code-buttons-container:not(:hover) {
+ visibility: hidden;
+ }
}
& pre code {
@@ -776,50 +784,40 @@
/* Having absolute positioning here ensures that the element
doesn't scroll along with the code div in narrow windows */
position: absolute;
- top: 5px;
+ top: 4px;
right: 0;
padding: 0 4px;
/* Invisible unless <pre> is hovered. */
visibility: hidden;
z-index: 0;
-
- &::after {
- content: " ";
- position: absolute;
- height: 100%;
- width: 100%;
- z-index: -1;
- /* Blur the background behind the button container */
- backdrop-filter: blur(5px);
- /* Use a radial gradient to avoid obvious hard edges
- to the blur. */
- mask-image: radial-gradient(
- farthest-corner,
- hsl(0deg 0% 0% / 100%),
- hsl(0deg 0% 0% / 50%)
- );
- }
}
+ /* The properties of the code_external_link button are copied from the
+ copy-btn class in app_components.css. */
.code_external_link {
- /* Match the apparent size of the playground icon
- to the copy-to-clipboard icon. */
- font-size: 16px;
- /* Center the icon vertically in the link container. */
display: flex;
- align-content: center;
- /* The font-icon footprint still requires 2px of
- top padding to get better alignment with the
- copy-to-clipboard icon. */
- padding-top: 2px;
- /* The default icon and on-hover colors are inherited from <a> tag.
- so we set our own to match the copy-to-clipbord icon */
- color: hsl(0deg 0% 47%);
+ border-radius: 4px;
+ color: var(--color-copy-btn);
+ /* 2px at 16px/1em */
+ padding: 0.125em;
+ cursor: pointer;
- &:hover {
- color: hsl(200deg 100% 40%);
- text-decoration: none;
+ &:hover,
+ :focus-visible {
+ background-color: var(--color-copy-btn-square-bg-hover);
}
+
+ &:active {
+ background-color: var(--color-copy-btn-square-bg-active);
+ color: var(--color-copy-btn-square-active);
+ }
+ }
+
+ .copy_codeblock,
+ .code_external_link {
+ font-size: 1.1363em;
+ border: 1px solid var(--color-copy-btn-square-bg-active);
+ backdrop-filter: blur(20px);
}
}
diff --git a/web/templates/code_buttons_container.hbs b/web/templates/code_buttons_container.hbs
index f464cc22c26..d5ec1a77979 100644
--- a/web/templates/code_buttons_container.hbs
+++ b/web/templates/code_buttons_container.hbs
@@ -1,8 +1,11 @@
<div class="code-buttons-container">
- <span class="copy_codeblock copy-btn" data-tippy-content="{{t 'Copy code' }}" aria-label="{{t 'Copy code' }}" role="button">
+ <span class="copy_codeblock copy-btn copy-btn-square" data-tippy-content="{{t 'Copy code' }}" aria-label="{{t 'Copy code' }}" role="button">
<i class="zulip-icon zulip-icon-copy" aria-hidden="true"></i>
</span>
{{~#if show_playground_button~}}
- {{~> view_code_in_playground~}}
+ {{! Display the "view code in playground" option for code blocks}}
+ <span class="code_external_link">
+ <i class="zulip-icon zulip-icon-external-link playground-links-popover-container"></i>
+ </span>
{{~/if~}}
</div>
diff --git a/web/templates/view_code_in_playground.hbs b/web/templates/view_code_in_playground.hbs
deleted file mode 100644
index fa9572947d6..00000000000
--- a/web/templates/view_code_in_playground.hbs
+++ /dev/null
@@ -1,2 +0,0 @@
-{{! Display the "view code in playground" option for code blocks}}
-<a target="_blank" rel="noopener noreferrer" class="code_external_link"><i class="fa fa-external-link playground-links-popover-container"></i></a>