macvim-dev / macvim-dev/macvim

Implement native color picker support

Đang mở
#1,272 0 bình luận 4 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Feature Request
Ngôn ngữ chính
Vim Script
Star
7.9k
Fork
691
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Is your feature request about something that is currently impossible or hard to do? Please describe the problem.
I think it would be nice if MacVim supports native color picking. macOS provides a system color picker (NSColorPanel), and we could hook into it to allow Vim scripts to get the color picked by the user and update texts and whatnot. This feature is very useful for web development, but even things like developing Vim color schemes would benefit from this.

Describe the solution you'd like
We can provide provide an API that looks something like :call pick_color(callback, <options>). This will bring up a color panel that lets you pick the color. Once you are done, it will call the callback with the provided color, and the script can do whatever it wants.

<options> can specify a continuous mode (it's a feature of NSColorPanel) so that every time the user clicks on the color it will immediately send the color to the callback (without needing to close the panel) so it's much better for fast iteration. For example, the script can be hooked up so that every time it gets a new color it remotely commands Safari to reload the tab to preview the updated color you just picked.

Other options include: the current color, whether to force an output color space for the picked color (e.g. forcing the picked color to conform to sRGB), whether to use alpha or not.

Describe alternatives you've considered
There is already a plugin that does this (https://github.com/KabbAmine/vCoolor.vim) but it uses osascript to invoke AppleScript to activate a color picker. This way of invoking it doesn't provide a lot of customizable options (e.g. alpha vs no alpha), and it doesn't let you pick the colors in continuous mode. It's better to have native support.

Additional context
Ideally this can be made into a native Vim feature (e.g. Gtk also provides a color picker) so it can be used cross-platform. I would imagine the API needs some room for flexibility though (e.g. the Gtk one doesn't have continuous mode, and it appears it doesn't even let you pick a different color space like sRGB vs P3).

I'm not sure if this will work in terminal Vim. Probably not. You need an AppKit application in order to invoke this.

Also see VSCode's version of this: https://code.visualstudio.com/Docs/languages/css#_syntax-coloring-color-preview (it's not as powerful because it's just a built-in support for color picking in certain situations, but it's not an extensible API). Note that the other portion of previewing colors in place in Vim can be done in Vim 9 using virtual text (see https://www.reddit.com/r/vim/comments/wm08fl/simple_vim_9_virtual_text_example_for_hex_colors/)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Không có tệp hoặc bài kiểm thử nào trong repository được nêu tên; hãy bắt đầu bằng cách xác định phần tích hợp AppKit của MacVim và các điểm vào API Vim-script hiện có. Đọc hành vi của NSColorPanel theo các yêu cầu được đề xuất về callback, options, continuous mode, color-space và alpha. Được xem là hoàn thành khi một native API có thể trả về các màu đã chọn với các options được yêu cầu, đồng thời các giới hạn của MacVim/AppKit và terminal được giải quyết.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
macos, objective-c, vim
Lĩnh vực
api, desktop
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
30/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.