Skip to content

support for displaying images in webview#2262

Draft
mahmoodsh36 wants to merge 9 commits into
lem-project:mainfrom
mahmoodsh36:webview-image
Draft

support for displaying images in webview#2262
mahmoodsh36 wants to merge 9 commits into
lem-project:mainfrom
mahmoodsh36:webview-image

Conversation

@mahmoodsh36

Copy link
Copy Markdown
Contributor

No description provided.

@code-contractor-app

code-contractor-app Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

❌ Code Contractor Validation: FAILED

=== Contract: contract ===

✓ Code Contractor Validation Result
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📋 Contract Source: Repository

📊 Statistics:
  Files Changed:    13
  Lines Added:      942
  Lines Deleted:    133
  Total Changed:    1075
  Delete Ratio:     0.12 (12%)

Status: FAILED ❌

🤖 AI Providers:
  - codex — model: (Codex default)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠️ Violations Found (2):

[WARNING] max_files_changed
  Too many files changed: 13 > 10
  Limit: 10
  Actual: 13

[WARNING] max_total_changed_lines
  Too many lines changed: 1075 > 400
  Limit: 400
  Actual: 1075
📋 Contract Configuration: contract (Source: Repository)
version: 2

trigger:
  paths:
    - "extensions/**"
    - "frontends/**/*.lisp"
    - "src/**"
    - "tests/**"
    - "contrib/**"
    - "**/*.asd"
  head_branches:
    exclude:
      - 'revert-*'

validation:
  limits:
    max_total_changed_lines: 400
    max_delete_ratio: 0.5
    max_files_changed: 10
    severity: warning

  ai:
    system_prompt: |
      You are a senior Common Lisp engineer reviewing code for Lem editor.
      Lem is a text editor with multiple frontends (ncurses, SDL2, webview).
      Focus on maintainability, consistency with existing code, and Lem-specific conventions.
    rules:
      # === File Structure ===
      - name: defpackage_rule
        prompt: |
          First form must be `defpackage` or `uiop:define-package`.
          Package name should match filename (e.g., `foo.lisp` → `:lem-ext/foo` or `:lem-foo`).
          Extensions must use `lem-` prefix (e.g., `:lem-python-mode`).

      - name: file_structure_rule
        prompt: |
          File organization (top to bottom):
          1. defpackage
          2. defvar/defparameter declarations
          3. Key bindings (define-key, define-keys)
          4. Class/struct definitions
          5. Functions and commands

      # === Style ===
      - name: loop_keywords_rule
        prompt: |
          Loop keywords must use colons: `(loop :for x :in list :do ...)`
          NOT: `(loop for x in list do ...)`

      - name: naming_conventions_rule
        prompt: |
          Naming conventions:
          - Functions/variables: kebab-case (e.g., `find-buffer`)
          - Special variables: *earmuffs* (e.g., `*global-keymap*`)
          - Constants: +plus-signs+ (e.g., `+default-tab-size+`)
          - Predicates: -p suffix for functions (e.g., `buffer-modified-p`)
          - Do NOT use -p suffix for user-configurable variables

      # === Documentation ===
      - name: docstring_rule
        prompt: |
          Required docstrings for:
          - Exported functions, methods, classes
          - `define-command` (explain what the command does)
          - Generic functions (`:documentation` option)
          Important functions should explain "why", not just "what".
        severity: warning

      # === Lem-Specific ===
      - name: internal_symbol_rule
        prompt: |
          Use exported symbols from `lem` or `lem-core` package.
          Avoid `lem::internal-symbol` access.
          If internal access is necessary, document why.

      - name: error_handling_rule
        prompt: |
          - `error`: Internal/programming errors
          - `editor-error`: User-facing errors (displayed in echo area)
          Always use `editor-error` for messages shown to users.

      - name: frontend_interface_rule
        prompt: |
          Frontend-specific code must use `lem-if:*` protocol.
          Do not call frontend implementation directly from core.
        severity: warning

      # === Functional Style ===
      - name: functional_style_rule
        prompt: |
          Prefer explicit function arguments over dynamic variables.
          Avoid using `defvar` for state passed between functions.
          Exception: Well-documented cases like `*current-buffer*`.

      - name: dynamic_symbol_call_rule
        prompt: |
          Avoid `uiop:symbol-call`. Rethink architecture instead.
          If unavoidable, document the reason.

      # === Libraries ===
      - name: alexandria_usage_rule
        prompt: |
          Alexandria utilities allowed: `if-let`, `when-let`, `with-gensyms`, etc.
          Avoid: `alexandria:curry` (use explicit lambdas)
          Avoid: `alexandria-2:*` functions not yet used in codebase

      # === Macros ===
      - name: macro_style_rule
        prompt: |
          Keep macros small. For complex logic, use `call-with-*` pattern:
          ```lisp
          (defmacro with-foo (() &body body)
            `(call-with-foo (lambda () ,@body)))
          ```
          Prefer `list` over backquote outside macros.

💬 Feedback

Reply to a violation comment with:

  • /dismiss <reason> - Report false positive or not applicable
📚 About Code Contractor

Declarative Code Standards That Learn and Improve

Define domain-specific validation rules in YAML.
Your contracts document team knowledge and evolve into more accurate AI enforcement.

Want this for your repo?
Install Code Contractor

@code-contractor-app code-contractor-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Contractor validation failed ❌ — see the sticky comment for full results.

@mahmoodsh36

Copy link
Copy Markdown
Contributor Author

this introduces functionality to display in webview, the functionality exists in the sdl2 frontend but not in webview.

the functionality so far is very basic and only works properly with images that originate from attributes of virtual text that originates from an overlay, by virtual text i mean the :before-item/:after-item stuff that was introduced in #2230, because the cursor is meant to skip over those virtual items. and currently when the cursor goes over non-virtual images the buffer gets confused.

the core currently uses a uniform grid for displaying text which makes it hard to work with arbitrarily sized objects so we round image sizes to multiples of cell sizes.

selecting text with cursor doesnt work because images dont align with the buffer flow so the client doesnt properly resolve cursor click position relevant to the text grid. hoping to addess this soon.

@mahmoodsh36

Copy link
Copy Markdown
Contributor Author

example usage:

(lem:define-command webview-image-demo () ()
  (let* ((image (namestring (asdf:system-relative-pathname :lem #p"resources/lem.png")))
         (attr (lem:make-attribute :plist (list :image image :pixel-width 300 :pixel-height 150)))
         (buffer (lem:make-buffer "*image-demo*"))
         (point (lem:buffer-point buffer)))
    (lem:switch-to-buffer buffer)
    (lem:erase-buffer buffer)
    (lem:insert-string point (format nil "before X after~%more text~%"))
    (lem:with-point ((s point)
                     (e point))
      (lem:buffer-start s)
      (lem:character-offset s 7)
      (lem:move-point e s)
      (lem:character-offset e 1)
      (let ((ov (lem:make-overlay s e attr)))
        (lem:overlay-put
         ov
         :cursor-enter-functions (list 'lem:move-point-out-of-overlay))))
    (lem:buffer-start point)))

@mahmoodsh36 mahmoodsh36 marked this pull request as draft July 4, 2026 20:17
@mahmoodsh36 mahmoodsh36 marked this pull request as ready for review July 4, 2026 20:18
@mahmoodsh36 mahmoodsh36 marked this pull request as draft July 4, 2026 20:18

@code-contractor-app code-contractor-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Contractor validation failed ❌ — see the sticky comment for full results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant