Skip to content

Improve markdown textarea for indentation and lists #31406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 21, 2024

Conversation

wxiaoguang
Copy link
Contributor

@wxiaoguang wxiaoguang commented Jun 18, 2024

Almost works like GitHub

  • use Tab/Shift-Tab to indent/unindent the selected lines
  • use Enter to insert a new line with the same indentation and prefix

image

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 18, 2024
@wxiaoguang wxiaoguang added the type/enhancement An improvement of existing functionality label Jun 18, 2024
@wxiaoguang wxiaoguang added this to the 1.23.0 milestone Jun 18, 2024
@silverwind
Copy link
Member

silverwind commented Jun 18, 2024

I wonder if we can add a test for this stuff. I assume basic textarea interaction should be possible with happy-dom, but I'm not sure whether that implementation is complete. Worth a try.

Another option may be to test it in playwright, but I don't consider our playwright tests in a usable state yet, but it's been something I wanted to take a look eventually.

@wxiaoguang
Copy link
Contributor Author

I wonder if we can add a test for this stuff. I assume basic textarea interaction should be possible with happy-dom, but I'm not sure whether that implementation is complete. Worth a try.

I could do it later, by unit test.

@wxiaoguang
Copy link
Contributor Author

I wonder if we can add a test for this stuff. I assume basic textarea interaction should be possible with happy-dom, but I'm not sure whether that implementation is complete. Worth a try.

I could do it later, by unit test.

I mean, in a separate PR in the future. This PR would also help other features like "image file drag"

@silverwind
Copy link
Member

Ok, but be prepared to run into happy-dom bugs 😆. If a unit test can do it, it would be great, much faster and much less overhead than playwright.

@wxiaoguang
Copy link
Contributor Author

So let's merge this as-is?

@silverwind
Copy link
Member

Can you describe a bit what this does? I'm not familiar to this GitHub functionality.

// when pasting links over selected text, turn it into [text](link), except when shift key is held
const {value, selectionStart, selectionEnd, _shiftDown} = textarea;
if (_shiftDown) return;
function handleClipboardText(textarea, e, text, isShiftDown) {
Copy link
Member

@silverwind silverwind Jun 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function handleClipboardText(textarea, e, text, isShiftDown) {
function handleClipboardText(textarea, e, text, {isShiftDown} = {}) {

Better to have options argument, also easier to read at caller site.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think it's worth to have an option here. It is not optional.

Copy link
Member

@silverwind silverwind Jun 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could remove the = {} to make it required, but I guess current 4 args is borderline acceptable. Still I prefer options arg because it's immediately clear what it does at the call site. Your variant is a boolean trap.

Copy link
Contributor Author

@wxiaoguang wxiaoguang Jun 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I do not see any difference between handleClipboardText(el, text, e, isShiftDown) vs handleClipboardText(el, text, e, {isShiftDown}) for callers. {} doesn't help readability.
  2. I am just removing the legacy el._shiftDown, and it doesn't really cause "boolean trap" because it only uses variables, no true/false trick.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I am the man who keeps removing the "boolean trap" from Gitea's codebase:

image

Copy link
Contributor Author

@wxiaoguang wxiaoguang Jun 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this.

  • Before: GenerateEmailAvatarLink( true/false )
  • After: GenerateEmailAvatarFastLink / GenerateEmailAvatarFinalLink

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, if you still have the variable name at caller site, that's fine.

@wxiaoguang
Copy link
Contributor Author

Can you describe a bit what this does? I'm not familiar to this GitHub functionality.

Added some comments, and most review suggestions are applied 358cd19

@silverwind
Copy link
Member

Ah I understand, yes those are some nice features.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 19, 2024
@wxiaoguang wxiaoguang requested a review from delvh June 20, 2024 16:50
@silverwind silverwind changed the title Improve markdown textarea for indention and lists Improve markdown textarea for indentation and lists Jun 20, 2024
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 21, 2024
@wxiaoguang wxiaoguang enabled auto-merge (squash) June 21, 2024 08:09
@wxiaoguang wxiaoguang merged commit 621e1ff into go-gitea:main Jun 21, 2024
26 checks passed
@wxiaoguang wxiaoguang deleted the improve-editor branch June 21, 2024 10:10
silverwind added a commit to silverwind/gitea that referenced this pull request Jun 21, 2024
* origin/main: (21 commits)
  Fix deprecated Dockerfile ENV format (go-gitea#31450)
  README Badge maintenance (go-gitea#31441)
  Improve markdown textarea for indentation and lists (go-gitea#31406)
  Split common-global.js into separate files (go-gitea#31438)
  Fix the link for .git-blame-ignore-revs bypass (go-gitea#31432)
  Bump htmx to 2.0.0 (go-gitea#31413)
  Fix the wrong line number in the diff view page when expanded twice. (go-gitea#31431)
  Fix labels and projects menu overflow on issue page (go-gitea#31435)
  [Fix] Account Linking UpdateMigrationsByType  (go-gitea#31428)
  Fix markdown math brackets render problem (go-gitea#31420)
  Reduce `air` verbosity (go-gitea#31417)
  Fix new issue/pr avatar (go-gitea#31419)
  Increase max length of org team names from 30 to 255 characters (go-gitea#31410)
  [skip ci] Updated translations via Crowdin
  Refactor names (go-gitea#31405)
  Update JS dependencies, remove `eslint-plugin-jquery` (go-gitea#31402)
  Switch to upstream of `gorilla/feeds` (go-gitea#31400)
  Fix rendered wiki page link (go-gitea#31398)
  Refactor repo unit "disabled" check (go-gitea#31389)
  Refactor route path normalization (go-gitea#31381)
  ...
zjjhot added a commit to zjjhot/gitea that referenced this pull request Jun 22, 2024
* giteaofficial/main:
  Refactor image diff (go-gitea#31444)
  [skip ci] Updated translations via Crowdin
  Support relative paths to videos from Wiki pages (go-gitea#31061)
  Fix deprecated Dockerfile ENV format (go-gitea#31450)
  README Badge maintenance (go-gitea#31441)
  Improve markdown textarea for indentation and lists (go-gitea#31406)
  Split common-global.js into separate files (go-gitea#31438)
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Sep 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/js type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants