1- import { getAllComps , getTextLayersByComp } from '../utils' ;
2- import { ProjectIssueType , type TextLayerIssues } from './types' ;
1+ import type { TextLayerIssues } from 'plainly-types' ;
2+ import { getTextLayersByComp } from '../utils' ;
3+ import { ProjectIssueType } from '.' ;
34
4- function checkTextLayers ( ) : TextLayerIssues [ ] {
5- const comps = getAllComps ( app . project ) ;
6- const textLayers : TextLayerIssues [ ] = [ ] ;
5+ function validateTextLayers ( comps : CompItem [ ] ) : TextLayerIssues [ ] {
6+ const textLayersIssues : TextLayerIssues [ ] = [ ] ;
77
88 for ( let i = 0 ; i < comps . length ; i ++ ) {
99 const comp = comps [ i ] ;
@@ -24,11 +24,10 @@ function checkTextLayers(): TextLayerIssues[] {
2424 // this checks only the first character of the text layer
2525 // IMPORTANT: with this method, on older versions (< 24.3), we can't fix, but we can at least report it
2626 if ( textDocument . allCaps ) {
27- textLayers . push ( {
27+ textLayersIssues . push ( {
2828 type : ProjectIssueType . AllCaps ,
2929 layerId : layer . id . toString ( ) ,
3030 layerName : layer . name ,
31- text : true ,
3231 } ) ;
3332 continue ;
3433 }
@@ -52,11 +51,10 @@ function checkTextLayers(): TextLayerIssues[] {
5251 cRange . fontCapsOption === FontCapsOption . FONT_ALL_CAPS
5352 ) {
5453 hasCharacterAllCaps = true ;
55- textLayers . push ( {
54+ textLayersIssues . push ( {
5655 type : ProjectIssueType . AllCaps ,
5756 layerId : layer . id . toString ( ) ,
5857 layerName : layer . name ,
59- text : true ,
6058 } ) ;
6159 break ;
6260 }
@@ -73,17 +71,16 @@ function checkTextLayers(): TextLayerIssues[] {
7371 range . isRangeValid &&
7472 range . fontCapsOption === FontCapsOption . FONT_ALL_CAPS
7573 ) {
76- textLayers . push ( {
74+ textLayersIssues . push ( {
7775 type : ProjectIssueType . AllCaps ,
7876 layerId : layer . id . toString ( ) ,
7977 layerName : layer . name ,
80- text : true ,
8178 } ) ;
8279 }
8380 }
8481 }
8582
86- return textLayers ;
83+ return textLayersIssues ;
8784}
8885
8986/**
@@ -138,10 +135,28 @@ function fixAllCapsIssue(layerId: string) {
138135 updateLayerTextDocument ( layer , newValue ) ;
139136}
140137
138+ /**
139+ * Fixes all caps issues for multiple text layers in a single undo group.
140+ *
141+ * **NOTE**: Works only on `After Effects 24.3` and later due to the use of `characterRange` method and `fontCapsOption`.
142+ *
143+ * @param layerIds Array of layer IDs to fix
144+ * @returns The name of the undo group created, or undefined if no fixes were applied
145+ */
146+ function fixAllCapsIssues ( layerIds : string [ ] ) {
147+ app . beginUndoGroup ( 'fix all caps' ) ;
148+
149+ for ( const layerId of layerIds ) {
150+ fixAllCapsIssue ( layerId ) ;
151+ }
152+
153+ app . endUndoGroup ( ) ;
154+ }
155+
141156function updateLayerTextDocument ( layer : TextLayer , newValue : TextDocument ) {
142157 const originalLayerName = layer . name ;
143158 layer . sourceText . setValue ( newValue ) ;
144159 layer . name = originalLayerName ; // Preserve original layer name
145160}
146161
147- export { checkTextLayers , fixAllCapsIssue } ;
162+ export { validateTextLayers , fixAllCapsIssue , fixAllCapsIssues } ;
0 commit comments