* 根据触发方式去除末尾的触发符号
(text: string, triggerType: string)
| 777 | * 根据触发方式去除末尾的触发符号 |
| 778 | */ |
| 779 | function removeTriggerSymbols(text: string, triggerType: string): string { |
| 780 | if (!text || triggerType === 'disabled' || triggerType === 'ctrl_enter') { |
| 781 | return text; |
| 782 | } |
| 783 | |
| 784 | let triggerSymbol = ''; |
| 785 | switch (triggerType) { |
| 786 | case 'triple_space': |
| 787 | triggerSymbol = ' '; |
| 788 | break; |
| 789 | case 'triple_equal': |
| 790 | triggerSymbol = '='; |
| 791 | break; |
| 792 | case 'triple_dash': |
| 793 | triggerSymbol = '-'; |
| 794 | break; |
| 795 | default: |
| 796 | return text; |
| 797 | } |
| 798 | |
| 799 | // 去除末尾所有的触发符号 |
| 800 | let cleanedText = text; |
| 801 | while (cleanedText.endsWith(triggerSymbol)) { |
| 802 | cleanedText = cleanedText.slice(0, -1); |
| 803 | } |
| 804 | |
| 805 | return cleanedText.trim(); |
| 806 | } |
| 807 | |
| 808 | /** |
| 809 | * 设置输入框中的文本 |
no outgoing calls
no test coverage detected