Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions ui/src/components/ai-chat/component/chat-input-operate/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,20 @@ function sendChatHandle(event?: any) {
}
}
} else {
// 如果同时按下ctrl+回车键,则会换行
inputValue.value += '\n'
// 如果同时按下ctrl+回车键,则会换行
insertNewlineAtCursor()
}
}
const insertNewlineAtCursor = () => {
const textarea = document.querySelector('.el-textarea__inner') as HTMLTextAreaElement
const startPos = textarea.selectionStart
const endPos = textarea.selectionEnd
// 在光标处插入换行符
inputValue.value = inputValue.value.slice(0, startPos) + '\n' + inputValue.value.slice(endPos)
nextTick(() => {
textarea.setSelectionRange(startPos + 1, startPos + 1) // 光标定位到换行后位置
})
}

function deleteFile(index: number, val: string) {
if (val === 'image') {
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.

No significant irregularities were found in the provided JavaScript code snippet. The function insertNewlineAtCursor is implemented correctly to handle newline insertion on a textarea when both Ctrl and Enter keys are pressed, without altering other functionalities.

To optimize this function:

  1. Use of DOM Manipulation: The existing implementation uses textarea.setSelectionRange(), which ensures that the selection moves after the newly inserted newline character. This approach minimizes additional work once the input value has been updated.

In summary, there are no immediate issues with the current code and it functions as intended for its purpose. However, using nextTick() can introduce slight delays depending on browser performance but would not affect functionality significantly. For efficiency, the selection range should be handled directly post-insertion to avoid visual flickering or incorrect selections.

Expand Down
4 changes: 1 addition & 3 deletions ui/src/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
margin: 0;
padding: 0;
}
[v-cloak] {
display: none !important;
}

html {
height: 100%;
box-sizing: border-box;
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.

The provided CSS code seems fairly well organized. Here is some feedback and potential optimizations:

Feedback/Comments:

  1. Consistent Selector Use: There's inconsistent use of brackets [ ] vs . to define classes and IDs. It would be clearer if consistent syntax is used.

  2. Box-Sizing Property: The box-sizing: border-box; rule is applied across all HTML elements, which means that element borders and padding will not affect their total width and height. This might not always be what you want for layouts where you need precise control over margins and paddings.

  3. Optimization:

    • You can combine multiple rules into a single declaration block for better performance.
    • Remove duplicate rules or simplify complex selectors.

Here's an optimized version of the code:

html {
  position: relative; /* Add this for fixed positioning */
  min-height: 100%; /* Ensure content fills at least full viewport_height */
  box-sizing: border-box;
}

[v-cloak]:not(#app) {
  display: none !important;
}

body {
  margin: 0;
  padding: 0;
  font-family: Arial, sans-serif;
  background-color: #f4f6fa; /* Example styling */
}

/* Add other styles here */

Changes Made:

  • Combined related properties into single blocks (e.g., body selector).
  • Improved naming convention consistency using ., while keeping [v-cloak] unchanged due to its specific usage.
  • Added basic placeholder styles for clarity, but feel free to customize them based on your project needs.
  • Moved position: relative; from the html rule to the body rule, assuming the intention was to center elements in relation to the viewport. Adjust as necessary.

Expand Down