loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ui: add copy path button to file view (#6079)

Port of https://github.com/go-gitea/gitea/commit/d11f8d24b0cd6b5a508df43c9e0912713cad9ce7.
Followup to https://codeberg.org/forgejo/forgejo/commit/187e10d8c9d8cd3edeb953e520ba370f2f1c73b3.

* removed `aria-label` in the diff template
* changed `Copy to clipboard` to `Copy path`
* left `copy_generic` for now, but it's unused
* ported the addition of this button to the file view template

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6079
Reviewed-by: Otto <otto@codeberg.org>
Co-authored-by: silverwind <me@silverwind.io>

0ko 4fbdd1fc af640ac4

+36 -1
+1
options/locale/locale_en-US.ini
··· 107 107 copy_generic = Copy to clipboard 108 108 copy_url = Copy URL 109 109 copy_hash = Copy hash 110 + copy_path = Copy path 110 111 copy_content = Copy content 111 112 copy_branch = Copy branch name 112 113 copy_success = Copied!
+1 -1
templates/repo/diff/box.tmpl
··· 130 130 </div> 131 131 <span class="file tw-flex tw-items-center tw-font-mono tw-flex-1"><a class="muted file-link" title="{{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}}" href="#diff-{{$file.NameHash}}">{{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}}</a> 132 132 {{if .IsLFSFile}} ({{ctx.Locale.Tr "repo.stored_lfs"}}){{end}} 133 - <button class="btn interact-fg tw-p-2" data-clipboard-text="{{$file.Name}}" data-tooltip-content="{{ctx.Locale.Tr "copy_generic"}}" aria-label="{{ctx.Locale.Tr "copy_generic"}}">{{svg "octicon-copy" 14}}</button> 133 + <button class="btn interact-fg tw-p-2" data-clipboard-text="{{$file.Name}}" data-tooltip-content="{{ctx.Locale.Tr "copy_path"}}">{{svg "octicon-copy" 14}}</button> 134 134 {{if $file.IsGenerated}} 135 135 <span class="ui label">{{ctx.Locale.Tr "repo.diff.generated"}}</span> 136 136 {{end}}
+1
templates/repo/home.tmpl
··· 113 113 <span class="breadcrumb-divider">/</span> 114 114 {{- if eq $i $l -}} 115 115 <span class="active section" title="{{$v}}">{{$v}}</span> 116 + <button class="btn interact-fg tw-p-2" data-clipboard-text="{{$.TreePath}}" data-tooltip-content="{{ctx.Locale.Tr "copy_path"}}">{{svg "octicon-copy" 14}}</button> 116 117 {{- else -}} 117 118 {{$p := index $.Paths $i}}<span class="section"><a href="{{$.BranchLink}}/{{PathEscapeSegments $p}}" title="{{$v}}">{{$v}}</a></span> 118 119 {{- end -}}
+33
tests/e2e/clipboard-copy.test.e2e.ts
··· 1 + // Copyright 2024 The Forgejo Authors. All rights reserved. 2 + // SPDX-License-Identifier: GPL-3.0-or-later 3 + 4 + // @watch start 5 + // templates/repo/home.tmpl 6 + // templates/repo/diff/box.tmpl 7 + // web_src/js/features/clipboard.js 8 + // @watch end 9 + 10 + import {expect} from '@playwright/test'; 11 + import {test} from './utils_e2e.ts'; 12 + 13 + test.use({ 14 + permissions: ['clipboard-write'], 15 + }); 16 + 17 + test('copy src file path to clipboard', async ({page}) => { 18 + const response = await page.goto('/user2/repo1/src/branch/master/README.md'); 19 + expect(response?.status()).toBe(200); 20 + 21 + await page.click('[data-clipboard-text]'); 22 + const clipboardText = await page.evaluate(() => navigator.clipboard.readText()); 23 + expect(clipboardText).toContain('README.md'); 24 + }); 25 + 26 + test('copy diff file path to clipboard', async ({page}) => { 27 + const response = await page.goto('/user2/repo1/src/commit/65f1bf27bc3bf70f64657658635e66094edbcb4d/README.md'); 28 + expect(response?.status()).toBe(200); 29 + 30 + await page.click('[data-clipboard-text]'); 31 + const clipboardText = await page.evaluate(() => navigator.clipboard.readText()); 32 + expect(clipboardText).toContain('README.md'); 33 + });